3 ms·
I find the GADT syntax used in the article hard to follow... Normally this is what I see, straight out of Jannis Limperg's insanely helpful compilation of langu
by hardwaresofton 7y ago
I find the GADT syntax used in the article hard to follow... Normally this is what I see, straight out of Jannis Limperg's insanely helpful compilation of language extension examples[0]:
data RestrictedMaybe a where
JustInt :: Int -> RestrictedMaybe Int
JustString :: String -> RestrictedMaybe String
Nothing :: RestrictedMaybe a
Maybe the intention was more of a "from scratch" implementation (without using extensions) but the above syntax is a bit easier to follow in my opinion IMO.
It might also be a good idea to make note of where the polymorphism is happening (the "a") and note how it's ok that the a is "resolved" in some of these constructors but not in the others.
[0]: https://limperg.de/ghc-extensions/#gadts https://limperg.de/ghc-extensions/#gadts
- anuragsoni 7y agoFWIW OCaml (the linked example is using reason, a different syntax for OCaml) doesn't need a syntax extension for GADTs. On a similar note i find the OCaml syntax easier to read than Reason's. (There is an option to toggle between the two in the linked website) The example from your post in OCaml: type 'a restricted_maybe = | JustInt : int -> int restricted_maybe | JustString : string -> string restricted_maybe | Nothing : 'a restricted_maybe
- acchow 7y agoThat’s essentially the same but with the type parameter appearing before the type name.