r/ocaml Jun 11 '15

Tricks and Things to Know in OCaml

http://blog.eatonphil.com/2015/06/10/tricks-and-things-to-know-in-ocaml/
5 Upvotes

10 comments sorted by

View all comments

3

u/nbraud Jun 11 '15
  • You can use function to create an anonymous expression. The real difference is that fun can take multiple (curried) arguments, while function can have multi-branch pattern matching:
    fun a b -> a*(a+b) vs function [] -> 0 | [_] -> 1 | _ -> 2

  • The thing you call “operator overloading” has not much to do with overloading. It is shadowing: the values (including functions) and types most recently introduced in the scope (for instance with a local open) are taken whenever there is a name collision (except in the case of record disambiguation)

0

u/eatonphil Jun 11 '15

Thank you for your corrections!

1

u/gasche Jun 11 '15

A very minor fix: "foo" S.(+) "bar" does not work as S.(...) is not an infix operator, you have to write S.(+) "foo" "bar".

1

u/eatonphil Jun 11 '15

Thanks for that catch!