4 ms·
You're right about the fact that on the left on `::` can never be anything other than the head of a list. But I'd like to add that throughout almost all OCaml
by flaie 14y ago
You're right about the fact that on the left on `::` can never be anything other than the head of a list.
But I'd like to add that throughout almost all OCaml code I've written and used to read, that type of matching was written:
match list with
| h::t ->
Wich reads easily `h` for `head` and `t` for `tail`. I'm surprised it hasn't been reproduced in the F# world.
`h::t` seems even better to me than `head`/`tail` or `x`/`xs` which for the second one, means nothing really to me.
- mich41 14y agoMaybe your code isn't famous enough. I've seen lots of x::xs's everywhere, but never a single h::t. Personally, I always use x::xs in one-liners and something meaningful (no, neither head nor h is meaningful) in longer matches.
- flaie 14y agoI've never mentioned my code as being famous. I've always used h and t in one-liners, maybe because of the person who taught me OCaml. H and t can also be found in the official Caml and batteries source code, along with hd/tl, a/l and probably x/xs if it pleases you. I can't agree more about naming variables correctly where it makes sense though.