
Generalized Algebraic Data Types: A Primer - tosh
https://sketch.sh/s/yH0MJiujNSiofDWOU85loX/
======
skybrian
This is interesting, but several of the examples are useless (such as HList)
or might not be a good idea in practice. Sometimes that's an easier way to
explain a concept, but it would be helpful to see more examples that show you
techniques that are actually recommended, rather than what not to do.

~~~
whateveracct
HLists actually aren't _useless_ in practice. I know I've used shapeless to do
some datatype-generic programming with them (deriving CSV rows from a case
class without reflection.)

Heterogenous unions are very similar and also extremely useful (multiple
effects libraries build on top of them).

------
hardwaresofton
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
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

~~~
acchow
That’s essentially the same but with the type parameter appearing before the
type name.

------
sushisource
Link just renders an empty page? On firefox, at least.

~~~
thangngoc89
Hello, I'm the main developer of Sketch.sh and there seems to be a problem
with the authentication server right now. I'm working on resolving it.

~~~
thangngoc89
Update: apparently I'm being rate limited.
[https://auth.sketch.sh/api/auth/webhook](https://auth.sketch.sh/api/auth/webhook)

Another kind of HN hug of death

~~~
kornish
Hmm, is that a Zeit thing or a Sketch.sh thing? Seems pretty worrying if a
service hosted on Zeit can't deal with HN frontpage-level load.

------
shrthnd
wtf is sketch.sh and why is it so awesome?

really though, this is a comfortable experience and the seamless live-coding
environment feels natural. nice work!

------
penguin_booze
Is is the latest trend to render markdown verbatim? Another recent post on HN:
[https://news.ycombinator.com/item?id=20211778](https://news.ycombinator.com/item?id=20211778)

~~~
spraak
Zeit.co does this too. I think it's weird

------
molyss
On my iphone, I can’t jump to the links, and if I try to select a URL, it
switches to edit mode and I can’t even switch tabs because the keyboard is
constantly taking over.

I was interested by the title but will skip the article because of poor UI

~~~
bo1024
I get nothing useful onscreen at all

------
mrvicadai
Can't wait for the DSL portion of the write up -- keep up the nice work!

------
bokumo
Since there is no explanatory text, this seems to be more of a testing
environment than a primer.

~~~
andywhite37
Try looking again - maybe you caught a version that didn't render correctly.
There is actually quite a bit of explanatory text, and it's quite good!

~~~
bokumo
Thank you, you are correct.

