Skip to content

Instantly share code, notes, and snippets.

@hadronized
Created January 20, 2023 23:50
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 hadronized/a0951c0ff46e2313603c7cba68be0105 to your computer and use it in GitHub Desktop.
Save hadronized/a0951c0ff46e2313603c7cba68be0105 to your computer and use it in GitHub Desktop.
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
@tamwile
Copy link

tamwile commented Jan 21, 2023

something like that :

data FooType = Int | Bool 

data Foo :: FooType -> Foo FooType

What's the difference ?

@hadronized
Copy link
Author

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