4 ms·
I think this is the first time I see anyone like the OCaml syntax.
by mookid11 10y ago
I think this is the first time I see anyone like the OCaml syntax.
- sfilargi 10y agoI think I like Reason's syntax better, but can't say I dislike Ocaml's.
- kibwen 10y agoAnd I believe Reason's syntax was inspired by Rust, so we've come full circle. :P
- macintux 10y agoI've not looked at OCaml, but when I discovered that ML's pattern matching works for function heads, I immediately became more interested. Pattern matching for function heads is magical. Thus sayeth the Erlang fanboi.
- chwind 10y agowhat is a function head?
- ZephyrP 10y agoIn some languages, a function can be defined multiple times with different signatures (multiple 'heads'). It will try each clause until it finds one that matches, allowing you to filter or change course on the basis of the value or characteristics of the arguments. This allows you to easily create special logic for corner cases and is generally extremely useful.
- aaron-santos 10y agoPattern matching can be used in the parameter list of function's definition.
- macintux 10y agoIf you look at the Wikipedia article for Greatest Common Divisor, you see this: gcd(a, 0) = a gcd(a, b) = gcd(b, a mod b) That, in effect, is what pattern matching + function heads gives you. You can copy that function directly into ML or Erlang, modulo a couple tiny bits of syntax. gcd(A, 0) -> A; gcd(A, B) -> gcd(B, A rem B).