Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
{-# LANGUAGE RankNTypes #-}
module Bug where
import Data.Functor.Identity
newtype T f = MkT { unT :: forall a. f a }
works1 :: T Identity -> T Identity
works1 (MkT x) = MkT x
doesn'tWork :: T Identity -> T Identity
doesn'tWork (MkT x) =
case x of
Identity y -> MkT (Identity y)
Bug.hs:14:24: error:
• Couldn't match type ‘a’ with ‘a0’
‘a’ is a rigid type variable bound by
a type expected by the context:
forall a. Identity a
at Bug.hs:14:19-34
Expected type: Identity a
Actual type: Identity a0
• In the first argument of ‘MkT’, namely ‘(Identity y)’
In the expression: MkT (Identity y)
In a case alternative: Identity y -> MkT (Identity y)
• Relevant bindings include y :: a0 (bound at Bug.hs:14:14)
works2 :: T Identity -> T Identity
works2 (MkT x) =
let Identity y = x
in MkT (Identity y)
works3 :: T Identity -> T Identity
works3 (MkT x) = MkT (Identity (runIdentity x))
works4 :: T Identity -> T Identity
works4 (MkT x) =
MkT (case x of
Identity y -> Identity y)
works5 :: T Identity -> T Identity
works5 (MkT x) =
MkT (Identity (case x of
Identity y -> y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment