-
-
Save hadronized/a0951c0ff46e2313603c7cba68be0105 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
data Foo :: * -> * where -- the * -> * means that Foo expects a type to be concrete, so like Foo Int, Foo Bool, etc. | |
FooInt :: Int -> Foo Int | |
FooBool :: Bool -> Foo Bool | |
-- so the compiler can enforce that there is no way to build a Foo t where t is not either Int or Bool. | |
-- then, matching on Foo Int is exhaustive here: | |
matchIntOnly :: Foo Int -> Int | |
matchIntOnly (FooInt x) = x |
It would be
data FooType = FooInt Int | FooBool Bool
And you cannot inject get the « favor » (int or bool) at compile type of a FooType
, so your second line doesn’t make sense.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
something like that :
What's the difference ?