Skip to content

Instantly share code, notes, and snippets.

@RyanGlScott
Last active May 16, 2019 13:19
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 RyanGlScott/dba49db44881735c3476e8b2483e25d1 to your computer and use it in GitHub Desktop.
Save RyanGlScott/dba49db44881735c3476e8b2483e25d1 to your computer and use it in GitHub Desktop.
{-# 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