« Return to Thread: A simple question about a function

Re: "ocaml_beginners"::[] A simple question about a function

by Karl Zilles :: Rate this Message:

Reply to Author | View in Thread

Msam85 wrote:

> HI everyone.
>
> I'm new in Ocaml language, and I had tried to understand the following
> function, but Im not able.
>
> let op = function
>   p->fst p (snd p);;
>
> If I put it at the top level it shows me :
> val op :     ('a->'b)*'a ->'b = <fun>
>
> I think that p must be like ( , )  but if i trie to write op((+),3);;
> It shows me   -: int -> int = <fun>
>
> Can somebody tell me how this function works and what does it do ?

I know it's summer and all, but is this for a class?  The function is
pretty contrived.  Where did you find it?

I'll say that you're pretty close to figuring it out.  Try this:

# let new_function = op ((+), 3);;
val new_function : int -> int = <fun>
# new_function 5;;
- : int = 8


 « Return to Thread: A simple question about a function