Is this OCaml composition statement definition / expression correct?

let (++) fgx = f (gx) in let fx = x + 1 in let gx = x * 2 in (f++g) 1;; 
  • Is the expression correct?
  • It seems to me that the above code should be exactly the same as the definition of f++gx = 2 * x + 1 . Am I right?
+4
source share
1 answer

Your implementation of function composition is correct because:

(g ∘ f) (x) = g (f (x)) for all x in X

according to wikipedia

I get:

 - : int = 3 

at ocamlktop

+4
source

All Articles