this post was submitted on 29 Aug 2023
1 points (66.7% liked)
OCaml
242 readers
4 users here now
An industrial-strength functional programming language with an emphasis on expressiveness and safety. Website: www.ocaml.org
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I'm no OCaml expert and mostly I'm casually browsing.
The arguments presented read quite compelling. What are your thoughts? Does the conclusion make sense? Have you had any real world experience w/ GADTs that you could share?
I’ve tried something recently in a project with Dream.
Suppose you have an url like
/page/param1/param2/
: you want to be able to do three things:Of course, some pages will have two arguments, some other three, and you have to find a way represent this in the type system.
For this, I’ve used a gadt:
The string is the parameter name in the url (id, login, …) and the gadt make the representation for this parameter in the type system. This gives me a way to declare some urls in the application:
Then I have some some functions wihch handle this gadt:
Thanks for your reply. I'm still not sure if I have managed to wrap my head around this 😕 I guess I need to re-read the relevant chapter from RWO book. I'll post back here I'm finally able to understand
handler
in your case.If you want something more detailed, there is a library which does the same things (with more documentation inside :)) : https://github.com/anuragsoni/routes