Skip to content

Instantly share code, notes, and snippets.

@ttuegel
Created August 8, 2021 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttuegel/7ee274b2445a60f6d806043eeac7532c to your computer and use it in GitHub Desktop.
Save ttuegel/7ee274b2445a60f6d806043eeac7532c to your computer and use it in GitHub Desktop.
Unexpected behavior with Strict + DeriveFunctor
{-# LANGUAGE Strict #-}
{-# LANGUAGE DeriveFunctor #-}
module StrictDeriving where
newtype Id1 a = Id1 a
deriving (Functor, Show)
-- >>> fmap (const 2 . const undefined) (Id1 1)
-- Id1 2
-- >>> (fmap (const 2) . fmap (const undefined)) (Id1 1)
-- undefined
newtype Id2 a = Id2 a
deriving Show
instance Functor Id2 where
fmap f ~(Id2 a) = Id2 (f a)
-- >>> fmap (const 2 . const undefined) (Id2 1)
-- Id2 2
-- >>> (fmap (const 2) . fmap (const undefined)) (Id2 1)
-- Id2 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment