Skip to content

Instantly share code, notes, and snippets.

@charles-cooper
Last active January 17, 2016 17:30
Show Gist options
  • Save charles-cooper/2cea397ba24ecb017576 to your computer and use it in GitHub Desktop.
Save charles-cooper/2cea397ba24ecb017576 to your computer and use it in GitHub Desktop.
data Val a = Val Int deriving Show
instance Functor Val where
fmap _ (Val x) = Val x
coerce :: Val a -> Val b
coerce = fmap undefined
data Void
x :: Val Int
x = Val 1
y :: Val Void
y = coerce x
-- Fails typechecking with:
-- Couldn't match type ‘Int’ with ‘Void’
-- Expected type: Val Void
-- Actual type: Val Int
-- In the expression: x
-- In an equation for ‘z’: z = x
-- z :: Val Void
-- z = x
main = do
print x
print y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment