In OCaml, how can I both :
- pattern match on an argument
- and also bind the unmatched argument to a name ?
in haskell it is like
f arg@{..} = some code using both arg and its fields
In OCaml, how can I both :
in haskell it is like
f arg@{..} = some code using both arg and its fields
Use as. E.g.:
let f ((a, b) as original) =
if a > b then
(b, a)
else
original
or:
let g = function
| [] -> []
| (x :: _) as l -> x :: l