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: https://github.com/reflex-frp/reflex-gadt-api

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

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.

Rizary

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

codygman

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

Rizary

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)

https://github.com/LightAndLight/indexed-paths#applications

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