Question

let (++) f g x = f (g x) in
    let f x = x + 1 in
    let g x = x * 2 in
    (f++g) 1;;
  1. Is the above expression correct?
  2. It seems to me that the above code should be just like defining f++g x = 2 * x + 1. Am I correct?
Was it helpful?

Solution

Your implementation of function composition is correct, since :

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

according to wikipedia

I get :

- : int = 3

in ocamlktop

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top