GADT - real-world use cases - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

GADTs are used in reflex apps to model request / response types, and pass them in the wire (websockets, etc.) as JSON. This library just released to tie it all together:

Interact with a JSON-serialized API defined by a GADT in your reflex-dom application - reflex-frp/reflex-gadt-api

finally, do you think this library will replace the need on Servant in reflex world?

Sridhar Ratnakumar

This existed in rhyolite for a long while anyway. I never needed servant.


nice... I wanted to remove Servant from my head nowadays


I find servant really nice, why do you want to remove it besides being able to have an "isomorphic app"?


I find it nice too.. I just don't want it for my next reflex project because it feels too cumbersome for me when develop the project with it. Also, I have another project using another frontend beside haskell (GHCJS), and I feel I don't need servant in my backend. It's a matter of preference though.

Sridhar Ratnakumar

Another (very interesting) use for GADTs (at the kind-level)

From the first example,


Locked ---Unlock--> Closed ---Open--> Opened
  ^                 |   ^                |
  |                 |   |                |
  +-------Lock------+   +-----Close------+


data DoorS = Locked | Closed | Opened

data DoorG :: DoorS -> DoorS -> Type where
  Unlock :: DoorG Locked Closed
  Lock :: DoorG Closed Locked
  Open :: DoorG Closed Opened
  Close :: DoorG Opened Closed
A library for working with free categories. Contribute to LightAndLight/indexed-paths development by creating an account on GitHub.
Joel McCracken

I came up with a use case that we actually kinda need in our app