Skip to content

Instantly share code, notes, and snippets.

@dima-starosud
Created December 14, 2014 18:23
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 dima-starosud/d3b85cee6b2605fb135c to your computer and use it in GitHub Desktop.
Save dima-starosud/d3b85cee6b2605fb135c to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeFamilies, GADTs #-}
data OfInt (f :: * -> *) where
OfInt :: f Int -> OfInt f
type family F a where
F a = Maybe a
runF :: F Int -> OfInt F
runF = OfInt {- Error on this line:
Couldn't match type ‘F’ with ‘Maybe’
Expected type: F Int -> OfInt F
Actual type: Maybe Int -> OfInt Maybe
In the expression: OfInt
In an equation for ‘runF’: runF = OfInt
-}
type family G a where
G a = Either a Bool
runG :: G Int -> OfInt G
runG = OfInt {- Error on this line:
Couldn't match type ‘Bool’ with ‘Int’
Expected type: G Int -> OfInt G
Actual type: Either Int Int -> OfInt (Either Int)
In the expression: OfInt
In an equation for ‘runG’: runG = OfInt
-}
newtype D a = D (Either a Bool)
runD :: D Int -> OfInt D
runD = OfInt {- works perfectly -}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment