Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# syntactic sugar

Tags:

syntax

f#

F# clearly contains a lot of things that are syntactic sugar, and as I try to learn it--without the aid of a book--I am overwhelmed by the sheer variety of syntax. Is there a simpler "core" language hidden behind all that syntactic sugar? Is there a cheat sheet list of the syntactic sugars and how they map to the core language?

And hey, is there a reason F# requires a different "assignment" operator for function definitions than for lambdas, or was it a random decision? e.g. "let inc x = x+1" vs "fun x -> x+1"

like image 901
Qwertie Avatar asked Dec 02 '22 08:12

Qwertie


2 Answers

A great deal of F# syntax comes from OCaml - many OCaml programs will compile and run in F# with no changes.

Good starter links:

http://msdn.microsoft.com/en-us/fsharp/default.aspx

http://en.wikibooks.org/wiki/F_Sharp_Programming

http://lorgonblog.spaces.live.com/blog/cns!701679AD17B6D310!887.entry?_c=BlogPart

like image 109
Brian Avatar answered Jan 04 '23 23:01

Brian


Along with Brian's links, I'd like to pass along links to my own blog series, Why I Love F#, which covers some of the basics.

With regard to your second question, "let inc x = x+1" vs "fun x -> x+1" are two ways of expressing a function, but only the first one uses the assignment operator. In fact,

let inc x = x + 1

Is equivalent to:

let inc = (fun x -> x + 1)

The first is shorthand for the second, but the second might illuminate how all functions in F# are really lambdas bound to names.

like image 20
Dustin Campbell Avatar answered Jan 04 '23 22:01

Dustin Campbell