List Info

Thread: "ocaml_beginners"::[] Re: when do we need function key word




"ocaml_beginners"::[] Re: when do we need function key word
country flaguser name
United States
2007-05-22 04:18:54

> 1. I found In many cases there is no "function" key word.
> 2. And how do we differentiate with evaluation?
>
> beginner, thanks!
>
> #let rec fib n =
> # if n < 2 then 1 else fib(n-1) + fib(n-2);;
> val fib : int -> int = <fun>;

I doubt it makes a lot of difference in generated machine code if
you write things this way, defining a closure without using any
parameter :

let rec fib = function
n -> if n < 2 then
1
else
fib(n-1) + fib(n-2);;

> I didn't find specific description in doc and only could learn from
codes.
Maybe Oreilly book [CMP00] could help ?
In first page, you have an index of keywords that references "function".

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )