Skip to content

Instantly share code, notes, and snippets.

@mstksg
Last active March 26, 2021 05:33
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 mstksg/f0568e8476b4e6075ab1d06376d0d930 to your computer and use it in GitHub Desktop.
Save mstksg/f0568e8476b4e6075ab1d06376d0d930 to your computer and use it in GitHub Desktop.
import Data.Coercible
newtype KM a x = KM (Maybe a)
newtype K1 a x = K1 a
data Id x = Id x
newtype IdF f x = IdF (f x)
data IdF' f x = IdF' (f x)
-- this works: K1 (Maybe a) x is coercible with KM a x
coerce (K1 (Just True)) :: KM Bool ()
-- this also works, if we wrap it in a non Higher Kinded data type
coerce (Id (K1 (Just True))) :: Id (KM Bool ())
-- this also works if we wrap it in a higher kinded newtype
coerce (IdF (K1 (Just True))) :: IdF (KM Bool) ()
-- but this doesn't work if we wrap it in higher-kinded data decl
coerce (IdF' (K1 (Just True))) :: IdF' (KM Bool) ()
{-
• Couldn't match representation of type ‘K1 (Maybe Bool)’
with that of ‘KM Bool’
-}
-- note the error is referring to the functor and not the fully saturated type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment