Created
August 8, 2021 14:56
-
-
Save ttuegel/7ee274b2445a60f6d806043eeac7532c to your computer and use it in GitHub Desktop.
Unexpected behavior with Strict + DeriveFunctor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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