Open benbellick opened 2 weeks ago
Of course the implementation would assume that a tuple is encoded as a list. Perhaps the functions could also take in a boolean flag that determines if the presence of extra items after the end of the tuple should cause a failure or not.
Also, then a decoder for e.g.
type x = Cstr of (int * string * bool * (int list))
would become
let x =
let+ i, s, b, l = D.field "Cstr" (tuple4 int string bool (list int)) in
Cstr(i,s,b,l)
Hi Matt,
Thinking it could be useful to have something like:
The value here is that the example from the
uncons
part of the documentation:could be rewritten as:
which seems a bit simpler. Then if you go into something more complicated than 4, you would use the more complex monadic uncons operation.
If you agree that this is a good idea, I'll submit a PR :)