Don Syme: Introduction to F#, Part 2
- Posted: Sep 14, 2006 at 10:59 AM
- 61,289 Views
- 30 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
That is SO confusing.
ChadK: Which part is confusing? Let's break it down!
I think that the start, moved too fast on. Really, the code seemed nonsense to me.
The Part 1, with the hello world seemed fine. No ;, i like!
The way you select things you want to run 6 minuts into the vidoe is quite cool, for debugging purposes, and in the case its used, where you show what impact each cal do.
What is the language aimed for? Scripting? Or is is supposed to be an anlternative to C#?
The lamda stuff with the events seemed cool. YET i think, like in some of the other stuff, just seemed comfusing, with all the strange characters that is use, like in the line containing the event with the lambda stuff, where did the "_" come from?
I think it was confusing for me, because theres so many characters like -, >, <, _ all over the place. In C#, to compare it with a language i know good, have an acceptable amount of that.
Part 4 seemed even more confusing.
for example in:
renderer.DrawScene.Add(fun _ -> bla bla...
renderer.DrawScene.Add takes a function as an argument, which itself takes an argument. So they pass an anonymus function, but since this function won't use it's argument, they don't give it a name.. just a _.
It is supposed to help with clearity when reading the code. had they written "fun x -> bla bla..." you might think, "what's this x? it doesn't seem to get used". Instead you put a "_" indicating that you are only accepting an argument to appease the type checker.
I believe that was a problem for som developers, who were working on a ML compiler for the Java VM.
Let me know if you want to get a walkthrough of the breadth of Windows Mobile devices that are shipping these days!
- Mike
I'm a long-time DirectX developer and a recent functional programming nutcase, and I was already excited to try F# before seeing this. Seeing this interactive demo knocked my socks off. There is amazing potential behind interactive simulations like this--experimenting with various renderers, techniques and even engines interactively can immensely speed up development and tweaking--you always have to tweak settings to make things look right. With this interactivity, you no longer have to build a special GUI for tweakability.
And physics! Tweaking physics parameters on the fly and observing their effects. Ow, what a bucket of PURE joy.
Fun days ahead!
Yep, the CLR has a tail call instruction, but mono does not, or at least didn't last time I checked. There is a compiler switch to turn tail call off so you can create mono comptable F# code.
I skiped the first part because I can't handle the go on focus and out of focus...
Lots of the syntax was different just for the sake of it. Why use "open" to reference a namespace instead of the far more intuitive "include" or "using"? What's with the return of "let"?! Why use "<-" instead of "=" - all different for the sake of it.
The 'coolness' of the demos wasn't F#, it was managed DirectX - which tells us a lot!
Perhaps I'm just not getting it, but F# seemed to be the quickest way to write reams of unreadable and unmanagable code.
A solution looking for a problem.
I occasionally thinks that a functional language might be helpful to create correct and effective programs that uses multi-core CPUs. This is because a "pure" functional language doesn't allow side-effects (modifying a member variable is a side effect).
FYI: Ericsson (you know the mobile phones) developed a functional language that they still use in their AXE line AFAIK.
http://en.wikipedia.org/wiki/Erlang_programming_language
Guaranteeing correctness is as far as I remember also one of the functional languages strong points.
Btw. a simple F# to solve the problems of the game tower of hanoi:
let rec hanoi n x y z =
match n with
| 0 -> []
| d -> List.append (hanoi (d-1) x z y) ((x,y)::(hanoi (d-1) z y x));;
hanoi 2 1 2 3;;
becomes
[(1, 3); (1, 2); (3, 2)]
Ie. for 2 bricks move brick from pin 1 to pin 3, from pin 1 to pin 2 and finally from pin 3 to pin 2.
I think this is a nerdy in-joke; I'm sure Don can correct me if I'm wrong: F#'s theoretical roots are the polymorphic, typed lambda calculus, otherwise known as System F. (Sounds kinda like Plan 9 From Outer Space to me.) Of course, to be .NET hip you have to be something-sharp, hence system F + # = F#.
F# is a general-purpose language so there are a lot of programs you would write in either F# or C#. Outside of the mainstream, F# and C# both have some specific niches where they excel: F# is great for writing compilers and mathsy stuff; C# has more of a systems programming feel--munging with pointers, structs and unsafe code.
In my experience F# is much more succinct than C#. That, with features like Python-style whitespace indentation and type inference, make F# feel much more "scripting" than C# does.
The comments are almost as good as the videos. I agree that the demos move quickly and the camera focusing and panning can be tough. As I recall, the demo at lang.net was more difficult because we couldn't see what Don was typing, just the results (and don't trust my memory for that).
The comments are also very useful in showing where the unfamiliar or the dissonant show up for people.
I've wanted to get back into the cockpit of a functional language for some time now, and it was easy to settle on F# as a place to start. My selection was motivated around its roots in ML and OCaml, which I want to know more about. And more than that, having the F# system be grounded on .NET provides yet another avenue to making use of all of the libraries and functions available on the CLI. It is sort of a nothing-to-loose investment and I can use F# where it covers a sweet spot for me, and use other programming systems when that's more appropriate.
As long as it runs on the CLI and inter-working of components works between F# and other .NET languages, this strikes me as very useful. So that's a bonus, for me, over firing up a Scheme compiler or some other not-yet-.NET functional language.
Most of the unusual syntax (open, let, <-, =, etc.) comes from Ocaml. The intersection of Ocaml and F# is large enough that you can write significant programs using only that subset and compile them as MSIL, Ocaml byte code, and Ocaml native code. In fact, this is how the F# compiler was bootstrapped: The F# compiler started life as an Ocaml program.
As language features are added to F# they tend to be very .NET-oriented, so the full F# language is definitely a new .NET language and not just an Ocaml variant.
F# syntax is fairly different from C#, and that can be overwhelming initially. To get a good feel for the language, why not look at the F# samples and try to write some toy programs? When you see something that feels foreign you're probably looking at an F# idiom that doesn't exist in C#. Sometimes in those seemingly dark corners lie the really cool differences between C# and F#.
Once you have some familiarity with the F# and aren't just stumbling over syntax, try writing some bigger examples. Maybe write something in C#, then in F#; then try another problem first in F# and then in C#. This is a good way to appreciate the difference between C# and F#. I'm pretty sure you'll get a feel for how "thinking in F#" can improve the design of your C# programs.
For example, in C#, when you have classes with virtual methods spread over various files, the F# programmer may think of discriminated unions and pattern matching (think of a virtual method call like a pattern match on the constructor). Then you appreciate some aspects of F# that are just unbelievably clean and cool. (Want to match on two values? It is very easy with pattern matching in F#. Doing a similar thing in C# is a bit messy and can lead to a bit of a code explosion.)
I've been noodling around with F# for quite a long time, so your experience as a newcomer to F# is very different than mine--which makes your insights doubly interesting. Please post to this forum; or on the F# community site, hubFS; or send me mail (dominic at dcooney dot com.)
Ciao,
Dominic
Part 1 at: http://www.mefeedia.com/entry/1143750
Part 2 at: http://www.mefeedia.com/entry/1160609
I an getting P2 as I make this post
like void and unit?? (i'm sure you know best all those construct that have had a synthax change, me i'm still new)
I guess some change could be nice but are you sure they are all necessery? I'm sure it would be easy just to redo at least the most evidant unnecesery naming change!!
I've use a lot of language (delphi,c,c#,vb, javascript etc....) and all of them had to use other syntax just to prove themselve different.
C# which use similar syntax to java is in my opinion a very clear syntax.
(i'm not talking about the specific part of the F# language but the identical parts to C#)
My brain is tired of translating everything languages construct everytime a new nice language come out and F# is so nice.
Anyway I guess your doing this because Microsoft told you this so that in the future they can incorporate F# in C#.
still why unit for void, why not void i can't understand hehehe in delphi a unit is a module not nothing... and unit??? i don't see the point of using a word like unit to represent nothing.
Anyway this is only my opinion as a starter with F#. I understand for people that are already totally in it that their language construct is what they want but heck it's always the same * a new language arrive.
I still think F# as a wonderfull future tho and I'll put the time to learn it but these days, all those C# changes + all the change that are coming from every libraries, my brain is so fucking tired, please every component and language programmers relax a bit for me to breathe hehehe
and i'm a young programmer hehhee how old programmers are doing these days???? I'm sure most are in the verge of depression hehhe
I still think those new tools/constructs/components are useful and will save me a lot of time but dam, they will all become mandatory and after so many years i'm still totally in books, guide, tutorials, videos, .....
hihihi
Hi PPL... for those who can't download the video by the link above you can use this instead... enjoy... ZEE!!!
http://download.microsoft.com/download/1/1/5/115186e6-3dbd-40f9-a4fb-d504869c9278/f-sharp-part2.wmv
Also very interesting about F# by Don...
http://www.infoq.com/interviews/F-Sharp-Don-Syme
Remove this comment
Remove this thread
close