type 'k leaf = {a_bb : 'k -> string;}
I'm unable to understand what this line of code in ocaml means. Can anyone help?
It declares a new type leaf parametrised over a type variable 'k which is a record type with one field a_bb of type 'k -> string where 'k is the parameter we mentioned before.
An example of a value of type 'k leaf would be:
{ a_bb = fun _ -> "Hello World!" }
But the 'k can also be specialised to a concrete type e.g.
{ a_bb = fun b -> if b then "Hello World!" else "Argh!" }
has the type bool leaf because the argument to the function in the field a_bb has to be a boolean for the expression if b then (...) to make sense.
You can access the function in the field a_bb by using a projection like so:
fun v -> v.a_bb