Re: [very beginner] function

"Esther Baruk [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <CAFzMiE3tNxcuPG=3ppGm8-by=343GJbUhV=m-6MUEonY7pBC2Q@mail.gmail.com>
Hi,

You can give a name to your function:

let f = function x -> x*x;;

f 5;;
- : int = 25

For function definitions, it is better to use the keyword "fun" instead of
"function".
"function" is used to do pattern matching on the argument of the function.

You can write f this way:

let f x  = x*x

or

let f = fun x -> x*x


For more details, you can read this page that explain the basics regarding
functions: http://ocaml.org/learn/tutorials/basics.html


Cheers,

Esther Baruk

On Mon, Nov 3, 2014 at 5:15 PM, [email protected] [ocaml_beginners] <
[email protected]> wrote:

>
>
> I understand this
>
> # function x -> x*x ;;
>
> But don't understand this
>
> # (function x -> x * x) 5 ;;
>
> It is a call of the function? Why do I have to put the complete
> function-definition again there?
> Isn't there a simpler way? Something like
>
> # x (5) ;;
> - : int = 25
>  
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.