News for hackers. Stuff that matters.
Re:Generalized Algebraic Data Types: A Primer by hardwaresofton on Tuesday June 18, 2019 @09:58PM (#20220212)
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

Re:Generalized Algebraic Data Types: A Primer by anuragsoni on Tuesday June 18, 2019 @10:46PM (#20220410)
FWIW 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
Re:Generalized Algebraic Data Types: A Primer by acchow on Wednesday June 19, 2019 @04:10PM (#20226861)
That’s essentially the same but with the type parameter appearing before the type name.