Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Generalized Algebraic Data Types: A Primer (sketch.sh)
182 points by tosh on June 18, 2019 | hide | past | favorite | 30 comments


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.


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).


Well HList gives you something which behaves like a tuple with generic size. The difference between an HList and a type like (a * (b * (c * unit))) is that the HList can use the regular list syntax which is much nicer to match on (especially with type constructor disambiguation). Eg one could imagine a varadic list map function which behaves a bit like map in lisps (ie accepting any positive number of lists). Although this would need multiple types that look like lists because of the lack of higher kinded types in reason/ocaml


>several of the examples are useless (such as HList)

I tried to use a similar (though more streamlined) Vinyl [1] for implementing database querying that glued and sliced records to match the queries, but alas, GHC choked and died on the type-level list operations. That was several years ago though and I didn't touch Haskell since then, maybe something has changed.

[1] https://hackage.haskell.org/package/vinyl


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


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


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


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


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.


Update: apparently I'm being rate limited. https://auth.sketch.sh/api/auth/webhook

Another kind of HN hug of death


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.


Hurry up, you're prime time on HN now!


Update: It's (partially) working again now.

You all can view the Sketch. Apology for the inconvenient.


If I try to scroll down on iPhone, it shows that a 500 error was hidden behind the nav/header.


It's probably a free-tier heroku app, being hugged to death right now. I've used this site quite a bit in the past on FireFox, Chrome, and Brave, and it has worked perfectly before.


Thank you. Like you said, I use Firefox for development and test it on Chrome as well.

The target users of Sketch.sh is web developers so I received bug reports about browser incompatibility almost instantly.

It was a problem with now.sh version 1 platform. I can't find a way to scale the free v1 node. All their docs prefer to upgrading to version 2 platform.


It does the same in chromium, so at least it's not a 'there's only one browser I develop for' situation...


Are you using NoScript? You have to enable scripts.


Looks like a graphql endpoint fails. 500 "invalid hook" ? After 10ish refreshes it worked... Qutebrowser here.


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!


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


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


This is forgivable because you can fork and edit it. Once you go from reading to editing, it is useful to see the markup. Many of us are used to reading verbatim markdown if your team uses readme.md in the git repo root of projects.


It is much more readable, especially in notebooks where "rendering" the markdown reflows the text and you get lost.


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


I get nothing useful onscreen at all


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


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


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!


Thank you, you are correct.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: