Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F#: Is the "fun" keyword necessary?

Tags:

I was typing the "fun" keyword and then I remembered you don't have to in C#

Wouldn't this:

List.map (x -> x + 1) [1..10]

Be just as expressive as this?:

List.map (fun x -> x + 1) [1..10]

This makes me curious as to why the "fun" keyword is necessary at all. Can someone clarify why the "fun" keyword is syntactically required?

like image 570
rysama Avatar asked Dec 18 '09 00:12

rysama


2 Answers

The language is ambiguous without it.

let x y = y z -> y z 

Does x call y on the function z -> y z or does it ignore its argument and return the function y z -> y z?

like image 142
Chuck Avatar answered Nov 24 '22 08:11

Chuck


Lots of decent speculative answers already... I'll add to the mix:

F# has a core language that's compatible with OCaml, and OCaml uses 'fun'.

like image 39
Brian Avatar answered Nov 24 '22 08:11

Brian