function - OCaml: Currying without defined values -


i have 2 functions f , g , trying return f(g(x)) not know value of x , not sure how go this.

a more concrete example: if have functions f = x + 1 , g = x * 2 , trying return f(g(x)) should function equal (x*2) + 1

it looks have right, f(g(x)) should work fine. i'm not sure why have return keyword there (it's not keyword in ocaml). here correct version,

let compose f g x = f (g x) 

the type definition is,

val compose : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c = <fun> 

each, 'a,'b,'c abstract types; don't care are, need consistent in definition (so, domain of g must in range of f).

let x_plus_x_plus_1 = compose (fun x -> x + 1) (fun x -> x * 2)  

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -