Indeed, and when I teach OCaml I find that students are surprised by this. Especially as beginners tend to give names to all their pattern holes and not just the ones that they are using: if there are not the same number of holes, then it doesn’t work. That being said, as an OCaml programmer, I wouldn’t mind this feature either, but it works best with the |
syntax of OCaml.
I’ve never taught O’Caml, so this is interesting. Isn’t this then a nice way to nudge those beginners into not giving a name to the holes in their patterns that they aren’t using?
Speculative: I would hope it would reduce the instances of
_ ->
because it’s easier to list the remaining cases, thus meaning that updates to a custom type are more likely to produce a compiler error where appropriate.
I think this is very important - there is a big semantic difference between “everything else” and “everything else, currently”, and the lack of this syntax encourages people to do the wrong thing.
I would think so but I can’t say I’m sure it had this effect, other than on this particular instance where it was necessary.
This makes the stuff in expr
be evaluated even if it doesn’t need to, though. Sometimes that matters.
EDIT: the solution is, of course, to extract whatever is the definition of expr
to a function, and call that.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.