Closed woeps closed 2 years ago
Hi @woeps
The error you see is related to value restriction. You can make shape
reusable by changing the definition to let shape () = pattern shape_to_string shape_of_string ":shape"
, and the route definitions to:
let r1 () =
(s "foo" / int / s "shape" / shape () /? nil) (* NOTE: this call is now using shape as well *)
@--> fun c shape -> Printf.sprintf "%d - %s" c (shape_to_string shape)
in
let r2 () = s "shape" / shape () / str /? nil in (* NOTE: str was s "create" previously *)
I mention value restriction in the docs https://github.com/anuragsoni/routes/blob/main/src/routes.mli#L8-L16 but there is room for improvement when it comes to documenting this better.
Oh, damn. I totally overlooked, that's what I already use for reusable paths. Somehow I didn't see, I could reuse pattern this way as well.
Thank you very much for taking your time to respond and explain it to me.
Hi, I tried to tinker a little bit more (since last year) with this great library and got into troubles when I was trying to use a custom
pattern
together withstr
in several paths.For examle take your routing_test.ml:288 "test custom pattern" and modify it like this:
This will yield a compiler error:
regarding
str
inIs it possible to reuse custom patterns?