문제

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?
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top