this post was submitted on 29 Aug 2023
1 points (66.7% liked)
OCaml
248 readers
1 users here now
An industrial-strength functional programming language with an emphasis on expressiveness and safety. Website: www.ocaml.org
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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