Now for something a bit stranger. What about a function which takes *anything *as an argument? Here’s an odd function which takes an argument, but just ignores it and always returns 3:

let give_me_a_three x = 3

What is the type of this function? In OCaml we use a special placeholder to mean “any type you fancy”. It’s a single quote character followed by a letter. The type of the above function would normally be written:

give_me_a_three : 'a -> int

(Hint: polymorphism is kind of like templates in C++ or generics in Java 1.5)

https://www2.ocaml.org/learn/tutorials/basics.html


🌱 Back to Garden