You are not authenticated, login.
text: sort by
tags: modified
type: chronology
hide / / print
ref: -0 tags: ocaml application functional programming date: 10-11-2022 21:36 gmt revision:2 [1] [0] [head]


From this I learned that in ocaml you can return not just functions (e.g. currying) but appliations of yet-to-be named functions.

let sum f = f 0 ;;
let arg a b c = c ( b + a ) ;;
let z a = a ;;


sum (arg 1) ;; 

is well-typed as (int -> `a) -> `a = <fun> e.g. an application of a function that converts int to `a. Think of it as the application of Xa to argument ( 0 + 1 ), where Xa is the argument (per type signature). Zero is supplied by the definition of 'sum'.

 sum (arg 1) (arg 2);; 

can be parsed as

(sum (arg 1)) (arg 2) ;; 

'(arg 2)' outputs an application of an int & a yet-to be determined function to 'a,

E.g. it's typed as int -> (int -> `a) -> `a = <fun>. So, you can call it Xa passed to above.

Or, Xa = Xb( ( 0 + 1 ) + 2)

where, again, Xb is a yet-to-be defined function that is supplied as an argument.

Therefore, you can collapse the whole chain with the identity function z. But, of course, it could be anything else -- square root perhaps for MSE?

All very clever.