Last active
December 22, 2016 08:21
-
-
Save merijn/77e3fa9757658e59b01d to your computer and use it in GitHub Desktop.
Haskell RankNType example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RankN where | |
data Foo = Foo Int | Bar Double | |
mangle :: Num a => (a -> a) -> Foo -> Foo | |
mangle f (Foo i) = Foo (f i) | |
mangle f (Bar d) = Bar (f d) | |
{- | |
NoRankN.hs:6:25: | |
Could not deduce (a ~ Int) | |
from the context (Num a) | |
bound by the type signature for | |
mangle :: Num a => (a -> a) -> Foo -> Foo | |
at NoRankN.hs:5:11-41 | |
‘a’ is a rigid type variable bound by | |
the type signature for mangle :: Num a => (a -> a) -> Foo -> Foo | |
at NoRankN.hs:5:11 | |
Relevant bindings include | |
f :: a -> a (bound at NoRankN.hs:6:8) | |
mangle :: (a -> a) -> Foo -> Foo (bound at NoRankN.hs:6:1) | |
In the first argument of ‘Foo’, namely ‘(f i)’ | |
In the expression: Foo (f i) | |
-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes #-} | |
module RankN where | |
data Foo = Foo Int | Bar Double | |
mangle :: (forall a . Num a => a -> a) -> Foo -> Foo | |
mangle f (Foo i) = Foo (f i) | |
mangle f (Bar d) = Bar (f d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment