An Interview With F# Creator Don Syme
OCatenac passes along an interview with Don Syme, chief designer of F#, which is Microsoft Research's offering for functional programming on the .Net platform. Like Scala, which we discussed last fall, F# aims at being an optimal blend of functional and object-oriented languages. "[Q] What is the best program you've seen written in F#? [A] I've mentioned the samples from F# for Scientists, which are very compelling... For commercial impact then the uses of F# in the finance industry have been very convincing, but probably nothing beats the uses of F# to implement statistical machine learning algorithms as part of the Bing advertisement delivery machinery. ... We've recently really focused on ensuring that programming in F# is simple and intuitive. For example, I greatly enjoyed working with a high-school student who learned F#. After a few days she was accurately modifying a solar system simulator, despite the fact she'd never programmed before. You really learn a lot by watching a student at that stage."
Will D flat be the same language as c#?
Obvious retort is why?
Sure, when everything works out. Something tells me F will mean something completely different when youre getting compiler errors or crashes.
and the emotive language and buzzwords
*yawn* unconvinced.
Last year I wanted to know what all the hoopla was about functional programming. I checked out Haskell, Scala, OCaML and F#. Coming from a Java/Delphi/C# background myself I had to go through it a couple of times before I "got" it. I'm glad I did because I banged out my first production IronPython lambda function on last Friday (yay!).
I know that MS bashing is popular here on Slashdot, but I really want to take a moment to say that the .NET Framework really is excellent. The ability to mix and match different paradigms and languages in a clean an concise manner which is a joy to program in.
Yeah I know patents bla bla mono bla bla Novell bla bla Miguel bla bla.
...of object-oriented and functional programming languages would be one without any functional perspective. I've learned both, I've managed both, and OO didn't drive me insane. Functional-based programming languages are syntactically inferior to OO ones, just as natural languages have features that make some more primitive than others.
"Please describe the scientific nature of the 'whammy'" - Agent Scully
If someone makes a debugger or syntax checker for it, will it be called 'F#CK'?
Slashdot: Where opinions are just opinions until you have mod points.
If you also know Java well, Groovy can also be an excellent tool, and is also useful in production environments.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
Dunno why exactly this was modded all the way down to -1, he has a good point.
// This is the time it takes jupiter to revolve around the sun (in earth days) // This is the same as above, but for earth.
A child "modifying a program" isn't very spectacular. Any moron with no experience can modify "hello world" to spit out "goodbye world". I'm quite certain that "modifying a solar system simulation" went something along the lines of this:
Problem 1:
Part A) Replace the values in the program with the proper values for the orbit of the planets.
int orbit_of_jupiter = 0;
int orbit_of_earth = 0;
void main()
{
lots of programming that is NEVER looked at or touched by the student;
}
Part B)
Record your results in the Excel spreadsheet and email it to the teacher. Then print out a copy and hand it in because the teacher isn't quite smart enough to open attachments in outlook.
I mean, seriously people. When you hear claims of "High school child modifying amazingly complicated programs that take years of know how to write correctly", think about it for a little bit. If it sounds too good to be true then it probably is. If F# were this amazing new language that allowed anyone with no experience to write any program, we'd have heard about it one hell of a long time ago.
-1 disagree is not a modifier for a reason. -1 troll, flaimbait, redundant, overrated are NOT acceptable substitutes.
As a longtime programmer in languages such as C++, Java, C# etc, and having explored many other dynamic and functional languages such as Perl, Python, Ruby, Haskell, and Lisp, I can honestly say that F# is now hands down my favorite language. There are a few reasons:
- it's like the best parts of all the paradigms rolled into one. Statically typed, but with automatic type inference to do most of the work for you. Fantastic generics - every function is generic without any of the scary syntax or mental overhead. First class functions, closures, all that good functional stuff. All the same objected oriented features you'd have in C#. All the garbage collection etc of the .NET platform. You can do things in almost any style you want and it never feels like you have to fight the language.
Of course, pick and choose your language, and you can find many of those features elsewhere. But here's the best part:
- it runs on .NET. You can use all of the .NET libraries, no need to hunt for and integrate third party libraries that are half implemented because of your wacky obscure language choice.
- you can sell it to your boss. Supported as an official MS product and included in Visual Studio 2010. Integrates flawlessly with C#. Has a great IDE already. Draw your WPF GUI in Expression Web if you feel like it and write the backend in F#.
Honestly I never want to go back. It's like that Paul Graham essay where he talks about how Lisp is so productive that his company killed the competition. Now I feel like every line of C#/C++ I write is a waste of my time.
FORTRAN has dug itself into a corner where it survives quite nicely. It's used for mathematical, engineering and scientific libraries. FORTRAN just seems to lend itself to expressing these sorts of problems better. Mind you, the whole program probably won't be written in FORTRAN - any UI code and other glue will be written in C. F# is filling the same niche for .NET - the mathematical and analytic libraries are being written in F# while C# is used for UIs and other glue. So even if it's a completely different paradigm, in spirit it's the FORTRAN of the CLR.
Python is good for many kinds of high-level code, but not all. Try processing a deep nested tree structure in it, for example (say, AST). Or writing a recursive descent parser.
Yes, you can do it, but it feels just as awkward as OOP done in plain C, after you see how it can be done in twice as little code with pattern matching in any FP language.
There's nothing wrong with either Python or C, of course. They have their own niches where they are near-perfect. In fact, the whole point of .NET is to let you take them all, and glue them together - so you can have performance-critical bits written in highly optimized C++ compiled to native code, seamlessly interoping with F# layer that implements computing logic, topped by IronPython layer which does UI using WPF.
There's one particular reason to look at F#, and that's FParsec. Parser combinators are just awesome, and don't get me wrong - I like the original Parsec, and Haskell in general! - but its IDE support is minimal, and debugging it is a pain.
With F#, you get the same awesome tool, but in an environment where you can actually use it for day-to-day jobs - write any parsing code as an F# library using FParsec, and call it from the main body of C#/VB/IronPython code.
As the "father" of F#, Don Syme had consulted pretty much all books written on the language so far, as well as those still being written. There's simply no better authority.
Something tells me F will mean something completely different when youre getting compiler errors or crashes.
fgrep??
Totally marketing garbage. Man is probably a great guy, with a lousy job. But F#, really? even .NET is ripping off Java. Microsoft talks about building "ecosystems" but the way they do it, everything in the ecosystem has to have a M$ logo on it. Why can't they just inter-operate and integrate with outside software?
I had a sig, but
He was probably modded as troll because, while he may be entirely correct about "marketing droids", the conclusion that "F# stinks" doesn't exactly follow from that - unless he has some specific horror stories to share. Or at least saw the language, and is qualified to judge on its merits (i.e. familiar with similar existing languages).
What if you need a complex program that's very reliable? I know it can be done in C and Python, but usually not without rigorous testing.
Well, C++ templates are unique. I don't know any other language that has a macro facility that pretends to be a generic type system... ~
Anyway, C++ was not original from language design perspective - it does indeed rip off Simula a lot - but who actually wrote anything in Simula? It was a very niche language, while C++ became mainstream. Most people who used it first saw all those Simula features in C++, and don't really know better. So "according to many developers", the assertion may even be correct...
It's very similar to how a lot of Java coders genuinely believe that Java was the one to pioneer OOP, and haven't even heard of Smalltalk, much less Simula.
I'm going to say something anathema to the /. crowd, but I'm looking into it with interest for replacing Python. I first teethed on FORTRAN, moved to Matlab 10 years lates, and have been using C extensively for the past 2 years. I'm starting into Python as a quick and dirty replacement for Matlab, and am quickly falling into a love-hate relationship with it.
The love comes from all the cool things that Python can do, for free. Dynamic typing, .append() functionality, etc. It's just awesome.
The hate comes from the sheer lunacy that is Python syntax. Forced whitespacing doesn't suit my debugging style (why not just have the compiler recognize either whitespace or accolades?); functions names like len() are just, frankly, idiotic (length() is much more readable to beginners, and takes only a few extra milliseconds to type for experienced users); and the way of working with indices is just weird (2:5 means the 2nd, 3rd, and 4th elements, but not the fifth; range(2 5) gives you 2 3 4, but not 5.).
Python reminds me of many of these incredibly powerful scientific projects that never got used by a non-scientist until it was far too late to make changes. range() is a good example of this, as while it perfectly emulates "for i=2; i < 5; i++", it is NOT what you expect to get when you say, outloud, "I want a range of numbers from 2 to 5". Having contributed to Scilab, I should know as I'm equally guilty of this kind of thing.
If F# can fill this void, by giving functional programming with functional syntax, I'll probably stop my Python experiments and move directly to F#.
Although to be honest, I'd love to find a python front end that uses non-insane syntax and then simply precompiles it into python syntax at run-time. Then you don't have the MS, Windows, and .Net ickiness.
P.S. I'm not looking to start a flame war about force whitespacing. There are really good reasons to like it. All my programs have consistent whitespacing, except when I debug (I like to put debug programming all the way against the margin, that way there's no possibility of ever forgetting it in the code)). However, you can't have it both ways on readability vis-à-vis function names and indices.
www.eissq.com/BandP.html Ball and Plate System. Amuse your friends. Crush your enemies.
He was probably modded as troll because, while he may be entirely correct about "marketing droids", the conclusion that "F# stinks" doesn't exactly follow from that - unless he has some specific horror stories to share. Or at least saw the language, and is qualified to judge on its merits (i.e. familiar with similar existing languages).
Looking at the wikipedia articles, I tend to think he has a point. Look at the F# version of the famous factorial program and compare to the Haskell version(s). I think anyone would be hard-pressed to prefer the F# version, but who knows?
Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
F# version is essentially the same as OCaml version. In practice, you will notice that there are a lot of people who prefer OCaml to Haskell even today, and that has to do with quality of implementation. Haskell is a nice language on the paper, but its laziness makes it both hard to implement fast, and insanely hard to debug.
With F#, you get language on par with OCaml (so less high-level and expressive than Haskell). But you also get the ability to directly call any existing .NET library - no wrappers or FFI declarations needed. Furthermore, you get an IDE with syntax highlighting, code completion, error checking as you type, and debugging.
Also, keep in mind that most people who get acquainted with F# today aren't familiar with Haskell. In fact, most of them don't even know it exists. They are C++, C# and VB users, who suddenly discover a new project type in VS2010, and are curious as to what this is all about. For them, the basis of comparison will be a typical imperative OO language, not Haskell - and most marketing materials are written with that in mind. It is generally assumed that people who know Haskell can judge these kind of things on their own :)
I understand that it is popular to bash anything that burst forth from the loins of Microsoft, but c'mon! This is Don, The Don, this is one hard-core damned brilliant programming dude (for want of a better term). He was single handedly responsible for generics in c# (something I am greatly thankful for in my day to day work) F# is his baby; the guy is passionate about the idea of a real world practical functional language. Sometimes people use emotive language when they are talking about things that they have devoted themselves to for years. Especially when they believe that it could bring functional programming into the mainstream. I have used F#, and personally really enjoy coding with it (and especially the different way in which solving problems in this manner makes you think). Might be a long time before it is excepted into production code though...
For those who don't have a clue but still have urge to comment, here is "hello world" in F#:
[start snipp]
#light
open System
printfn "Hello world\n"
Console.ReadKey(true)
[end snipp]
And another example illustrating what would would take a highschool kid to modify physics simulation:
[start snipp]
#light
open System
let gravity = -9.81
let euler_explicit accel pos speed delta =
pos + delta * speed, speed + delta * accel
let euler_implicit accel pos speed delta =
let speed2 = speed + delta * accel in
pos + delta * speed2, speed2
let pos, speed = euler_explicit gravity 0.0 0.0 1.0 in
printfn "pos = %f speed = %f\n" pos speed
let pos, speed = euler_implicit gravity 0.0 0.0 1.0 in
printfn "pos = %f speed = %f\n" pos speed
Console.ReadKey(true)
[end snipp]
(taken from http://sharp-gamedev.blogspot.com/2008_09_01_archive.html)
Cheers
nothing beats the uses of F# to implement statistical machine learning algorithms as part of the Bing advertisement delivery machinery
Are you SURE you want to promote that as a productive use of the language? Bring together two things that people love to hate? Even Google's ads are merely tolerated at best.
What's next, "F# for spammers"?
...of a functional language, it is simply Microsoft's offering of a functional language. The former statement sounds like it's one of the dozens of functional languages fostered in academia, for academia to play with. The whole difference here is that, as of Visual Studio 2010, F# becomes a fully productized and supported language in the .NET world. That's really what's exciting for functional language geeks, because never before a real, modern functional language of the generation built in academia in the 90s, like OCaml and Haskell, had such a mainstream backing.
F# version is essentially the same as OCaml version.
I don't know OCaml (I have a cursory knowledge of Haskell, which is why I picked that for comparison), but I could read the OCaml version no problem. The Scala version was difficult, but after staring at it for a bit I understands what it's getting at (especially the _ syntax is unnecessary obtuse). I still think F# is the worst of the lot. Big disclaimer: I have only looked at the factorial example. So this is sort of criticism based on "Hello World" snippets. I'm just saying that the poster far above might actually know what he is talking about,.
Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
Note there is nothing inherently functional about pattern matching.
It's just a feature that happens to be popular in the ML/Haskell world.
The equivalent with OO is a visitor. It tends to be more verbose due to lack of functional glue. But with anonymous classes or functions, it's not much more verbose anymore (and at least the parsing is clear to a human).
Don't you mean - yet more Vendor lock-in ..
WTF#
Looks like the languages are breeding. Look at the 'DNA' combining. Not Pretty. Lots of extinctions. If you can't stand the mess get out of the pool.
i do have horror stories to share. do you need to hear them?
F# isn't in Visual Studio 2008, is it? (I just checked Wikipedia, and no, it will be fully supported for the first time in VS2010.) What you have been working with isn't a production system yet. What horror stories about F# could you possibly have?
Aren't all the functional techniques in F# being pulled into C#? Like DryadLINQ, and other components from Microsoft?
--
make install -not war
If this is a functional language, it presumably makes generous use of recursion. Which brings up something I'd be interest in /. comments on...
There are a lot of algorithms that can best be expressed and (theoretically) most efficiently solved by recursion. However, (a) most programmers are not comfortable with recursion and (b) most programming languages (C++, C#, Java, etc.) make no optimization for recursion. In particular, they use a new stack frame for each recursion, even if the function is tail-recursive. This lack of optimization means that deeply recursive algorithms must be avoided - leading right back to (a).
My question for /. is simply: why? Why co modern OO languages not provide decent optimizations for recursion? Why are most programmers uncomfortable with it? What can be done to break this cycle?
Enjoy life! This is not a dress rehearsal.
Well, I may be stupid, but still. No, the match I understood as a funny way to write case statements. The -> is clear as well, but the 0l? I supposed l is for long, but I guess it meant "arbitrary precision integers" And the _? What's the deal with that? I also cannot guess what "rec" standard for. Compare this to the Haskell example:
Here, I see plain English (Integer) and only two magic symbol (::, ->), the latter of which should be plain for anyone having even a basic schooling in mathematics (where functions are usually written as f:X->Y, a syntax few programming languages use for some reason). Contrast this with the F# version: Magic symbols ( |, ->, l, _ ) and a slew of non-obvious words ( let, rec, match .. with .. ). I think the Haskell version is much, much cleaner.
In all cases, I have ignored the math symbols =,+,*,- etc as being common between almost every language out there, and thus irrelevant.
Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
Okay, I can see your point. The "rec" is definitely confusing and it's one of the things I would remove from the language. It's short for recursive and is required if your definition of the function is going to make a call to the function. I've never understood why that would be required.
I really think that "let" is pretty straightforward. If you've never heard a teacher or professor say "let f equal ..." then I'm not sure where you've gotten your mathematics background.
The "match" and "with" parts seem pretty straight-forward if you understand that what happens in any of these definitions is that the value of the variable is matched against possible patterns until it matches (same thing happens in Haskell with the multiple definitions of the function), but if you're new to them, I can understand the confusion.
And _ is definitely just a magic piece of punctuation whose role is not clear to the layman. In case you're curious, it's used to match anything. You might think that it would make more sense to use something like "what's left" or something like that, but the _ really is useful when doing more complex pattern matching because you can use it inside the pattern.
So I see what you mean. But I should note that all of these things (rec, match, with, _) come from Ocaml (from which F# is immediately derived. You can write Ocaml code and add one line and F# will compile it). The differences between Ocaml and F# in the wikipedia examples is primarily a difference in coding choices rather than syntax. You could use the if-style or the match-style version of the function in either language. (Not that I'm expecting you to know that because there's nothing in the wikipedia article which indicates this.)
Anyway, thanks for answering my question.
One can write a Haskell version of factorial that looks pretty much the same as the F# version:
This contains similar pattern matching expression, even using the same match-anything-pattern-keyword '_' and some additional polymorphism syntax in the type signature. The type signature could be left out and what's shown is what the compiler would then automatically derive.
I've never had a problem with python's whitespace parsing, but I read somewhere that python is so superior it has support for all the other schemes to denote blocks. For example, you can use 'begin' and 'end' keywords, you can also use braces {,} as well. Here's an example demonstrating python's superior syntax:
if foo == 3:
....block of code here....
....another block of code here....
#begin
#end
else:
#{
#}
You say you don't like 'len' as a name for a length function, that you would prefer using the name 'length'. Well, python is so superior, that you can fix that problem really fast in your code:
length = len
From your posting, you've got lots of experience number crunching. Have you taken a look at numpy and scipy? There optimized modules to give python the speed of fortran for doing linear algebra, statistics, etc. Want to do an svd,linear regression, sampling, etc. in python fast and easy? numpy is your best friend.
The one big showstopper I have with F# (which might (maybe) actually be an awesome language) is of course that it comes from Microsoft, who has a better proven history of screwing people and locking them into Windows than some Oil companies have of finding oil. On what platforms can I use this F# language? Please, no equivocating. I just want to be able to do: "sudo apt-get install F-sharp".
Why should I wrote code in a language that's bound to a platform/OS that's inferior to the one I use on a daily basis from a company who's trying to lock me into their products, when I have free easy access to code from people who don't have as an agenda screwing me over with their licenses, restrictions, treating me like a suspected criminal? If I want a functional programming language, I can run lisp, ocaml, haskell, ML, erlang, none of which restrict me as to which platform or OS I use.
vim has syntax highlighting for every programming language and file format known to man (well... nearly). Emacs, gedit, kate and others support a lot of different languages as well. However, Visual Studio only supports syntax highlighting for languages it can compile.
I hate code completion. If you mis-type something, the editor will fill out the wrong thing for you. For editing XML, you can't wrap some text in a tag, as Visual Studio auto-completes the end tag for you. I always type both quotes after an attribute, so end up with 3 quotes in Visual Studio! And yes, when I use Visual Studio, I have these turned off, thank-you-very-much!
Auto-complete for method names means that you end up playing hunt-the-function-name-game and don't necessarily understand what it is you are typing.
Error checking is good, but having it report that you need to close a parenthesis or XML tag as you are writing the document and haven't written that yet is very annoying.
Debugging in the one area where Visual Studio is very good, but well-written tests with good test coverage, and decent logging/error reporting should remove most of the need for debugging.
Has this improved any? I really would like to used F# on Linux, but I will not go anywhere near something with licensing like this?
As one might expect, you can get moderated as Flamebait if you say the same thing about opensource as somebody said about .Net.
The funny thing is that the moderator missed the point. The AC was mocking the logic of the other poster, not really making a statement about OSS projects.
Begin-End
Stop it you are giving me pascal flashbacks.
Got Code?
Are you going to make F# available under an open source license like Apache, BSD, or LGPL? The current shared source license really makes F# unattractive for both commercial and academic use. Given how much F# builds on OCAML, it would also only seem fair if F# itself becamse open source.
The -> is clear as well, but the 0l? I supposed l is for long, but I guess it meant "arbitrary precision integers"
Yes, it does. F# guys went for limited-precision integers (the usual 32-bit int) by default for performance reasons.
And the _? What's the deal with that?
It has the same meaning as in Haskell - it's a placeholder that matches anything, and doesn't bind the matched part to a variable.
"let rec" ("rec" means recursive) is used mainly so that you can redefine an existing variable in terms of itself. For example:
If "rec" was the default, the second "let" would have been invalid, since it references the variable in its own definition. I think Haskell would have actually let you get away with writing this because of its laziness - it'd just end up in an infinite loop if you ever evaluate x. F#, in contrast, isn't lazy.
In any case, I don't think anyone would argue that Haskell syntax is much closer to the traditional math notation - it's one of the explicit design goals for the language. However, there's more to it than syntax. For example, can you point out a decent Haskell IDE?
Note there is nothing inherently functional about pattern matching.
It's just a feature that happens to be popular in the ML/Haskell world.
Yes, I know. But so long as we stick to strict definitions, any language with first-class function values is functional, and sometimes this results in some unconventional classification.
So, in practice, when people talk about FP languages, they really mean a certain set of features, and first-class functions are only one part of that. Pattern matching had historically been another distinctive feature of the same class of languages.
The equivalent with OO is a visitor. It tends to be more verbose due to lack of functional glue. But with anonymous classes or functions, it's not much more verbose anymore (and at least the parsing is clear to a human).
Even with lambdas, visitors are still very verbose compared to pattern matching if only because you have to write the visiting code.
By the way, there's nothing precluding one from doing proper pattern matching with an OO type system, without any need for hacks such as visitors. Scala does just that.
However, there's more to it than syntax. For example, can you point out a decent Haskell IDE?
I did write, several times, that I was comparing languages by one example. Does that sound like I would know such stuff? Anyway, try this :P
Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
You say you don't like 'len' as a name for a length function, that you would prefer using the name 'length'. Well, python is so superior, that you can fix that problem really fast in your code:
length = len
That *is* a neat feature.
My only beef is that it can't help to solve the mess that is everyone else's Python code. Once I'm programming in Python, all these things will seem very natural. (It can't be worse than C!) But for people who are new to Python, and just want to modify a tiny section of code in someone's script because it almost, but not quite, does what they want it to, all the myriad Python bizarreness jumps up and bites them.
www.eissq.com/BandP.html Ball and Plate System. Amuse your friends. Crush your enemies.
"Debugging in the one area where Visual Studio is very good, but well-written tests with good test coverage, and decent logging/error reporting should remove most of the need for debugging."
That sounds like a case of "let's not bother debugging, we'll throw some more printf in there and see where it goes wrong." Debugging is much more powerful than simple test coverage and incorrect output - it allows you to do things like verify your error handling code paths work as expected, check why a program that works on one system but not another is failing (without having to recompile and deploy new binaries), and other stuff. Logging/error reporting is a poor substitute for proper debugging, especially in any non-trivial program.
vim has syntax highlighting for every programming language and file format known to man (well... nearly). Emacs, gedit, kate and others support a lot of different languages as well. However, Visual Studio only supports syntax highlighting for languages it can compile.
Not really. From plugin API point of view, syntax highlighting (and all language services) are entirely separate from the build system, so you absolutely can write a custom syntax highlighter for VS without doing the whole thing. It's just that few bother.
I hate code completion. If you mis-type something, the editor will fill out the wrong thing for you. For editing XML, you can't wrap some text in a tag, as Visual Studio auto-completes the end tag for you. I always type both quotes after an attribute, so end up with 3 quotes in Visual Studio! And yes, when I use Visual Studio, I have these turned off, thank-you-very-much!
I also find automatic code completion annoying, but what's wrong with pop-up hints that only show you the options, and don't impede you in just typing whatever you want?
Auto-complete for method names means that you end up playing hunt-the-function-name-game and don't necessarily understand what it is you are typing.
That's a weird argument. For one thing, if functions are well-named, usually you just pick what is right that way (I could even say that it encourages API designers to name their functions properly). Furthermore, code completion in VS also shows documentation for the function you select, so it's not like you pick blindly by name alone.
Error checking is good, but having it report that you need to close a parenthesis or XML tag as you are writing the document and haven't written that yet is very annoying.
Well, you just keep typing, and it goes away?
There's one other thing that an IDE gives, and that is particularly valuable in a language with pervasive type inference - quick type information: hover mouse over any identifier, and get its type. In a language like F#, I find that I tend to use it much more to see what the inferred types actually are.
You know, C++ is the language embodiment of Microsoft. It embraces and extends everything from everyone else, and yet manages to maintain market share with C compatibility.
Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
The problem is not that badly written programs fail. The problem is that even programs that were supposed to be well written in .NET crash miserably.
In the old days people would say "no one was ever fired for buying an IBM system". Well, there's at least one chief executive of a major corporation that has been fired for buying a .NET system.
It is impossible to combine a object oriented language with a functional language. Functional languages are about values. Values are closed. Values are the opposite of objects. Functional languages could only work on closed collections of objects as a whole, because such a collection would behave as an object. Any attempt to combine the two will lead to very strange and counter intuitive semantics where either one of the two has is seriously damaged. Either you get a functional language (working on collections of objects as a whole) or you get a object oriented language with non-functional semantics. Everybody who claims that functional and object oriented can be joined either does not understand what these words mean or have an alternative interprettation of what of either one of the two terms.
I'm aware of the difference, but even so, C programmers typically call them functions, not procedures, and I've been a C programmer for a lot longer than a functional programmer, so that's what I (and many imperative programmers) are accustomed to calling them. It isn't as if I don't think it's important to use words correctly, but I don't think it's productive to argue about who is using what word in the wrong way if my meaning is clear. If it isn't, then that's my mistake, then.
Common Lisp is definitely both functional and object orientated.
It's not in the Lisp family of languages. Or would you call those non-functional?
How many times does it need to be said?
I have not seen one and I mean one .NET program that can simply be recompiled to run on Unix. There are always problems or something dumb like winforms not being up to 1.0 equivalent due to them using COM.
Novel Zenworks is the only thing that comes close because it has 2 different software versions due to the incompabilities of Mono. The linux version sucks very bad.
The whole reason why Google Sketch does not have a Linux port is because of .NET. Its nearly impossible to port it.
At any given bookstore how many books on .NET do you see that do not show Visual Studio and instructions on how to use it? Visual Studio and .NET seem to confuse programmers as the same product. ... in actuality they are. .NET is part of Microsoft's Visual Studio tools of Windows only development.
Let me know when paint.net can simply be recompiled with a checkbox to GNU/mono?
Its about as portable as C++ in my opinion in that you need the right apis on multiple platforms. This is why Java was created.
http://saveie6.com/
The programs you linked are basically the same thing; Haskell just has a bit of extra syntactic sugar than the F# version. If you really understand either language, you can see that the function definition in the other maps pretty exactly to the one you know.
:: Integer -> Integer
:: Int -> Int
... with ...' pattern-matching expression corresponds to 'case ... of ...' in Haskell, and the symbols used are a bit different; (d) the Haskell definitions have a type constraint, and the F# doesn't (this is optional in both languages, but the syntax is different, and Haskell programmers have a habit of doing it much more frequently).
Here's the F# code that you link:
let rec factorial n =
match n with
| 0I -> 1I
| _ -> n * factorial (n - 1I)
Here's the Haskell one you link:
factorial
factorial 0 = 1
factorial n = n * factorial (n-1)
But here's the Haskell one rewritten to (a) not use multi-equation definitions, (b) use the Int type (limited precision, faster) instead of Integer (unlimited size). (That's my guess at what the "0I" and "1I" mean in the F# program--plain ints instead of bignums.)
factorial
factorial n =
case n of
0 -> 1
_ -> n * (factorial n-1)
Note how much the sugarless Haskell version looks like the OCaml. This is a family resemblance; Haskell, OCaml and Standard ML all descend from ML, and share many of the same basic concepts (functional, Hindley-Milner type system, algebraic datatypes, pattern matching). Haskell's got the nicer syntax of them, though.
Just to enumerate the differences between these pieces of code: (a) OCaml and F# require you to use 'let rec' when you define a value that refers to itself recursively, while Haskell and Standard ML allow all definitions to do so; (b) Haskell top-level definitions and some local bindings can be written in multi-equation style; (c) F#'s 'match
Are you adequate?
I've been using TextMate, Macfusion, and GHCi.
After all, I am strangely colored.
It is impossible to combine a object oriented language with a functional language.
You have to go tell OCaml authors that...
Functional languages are about values.
Not at all. I'm not sure what you mean by "values" here (I'll touch on that below), but the strict definition of a functional language is "a language that has functions as first-class values". That's all there is to it.
Values are closed. Values are the opposite of objects.
I think you need to provide your definition of "object" and "value" at this point. Are you referring to the fact that objects have inherent identity, while values do not? What about immutable objects, that are used solely for encapsulation and virtual dispatch (a la OCaml)? How are they any different from ADTs?
Or do you refer to immutability? It's not a hallmark of a functional language, either. For example, both Scheme and Standard ML have mutable values, but they're definitely functional. On the other hand, XQuery is pure - output is a strict function of input, no mutable state at all - but it doesn't have function types nor values, and so it's non-functional.
Everybody who claims that functional and object oriented can be joined either does not understand what these words mean or have an alternative interprettation of what of either one of the two terms.
"Alternative" relative to what? Yet again, you really need to provide your definitions for this to be comprehensible.
Common Lisp is a hard one to identify, but the majority tend to put it into the imperative category, because idiomatic CL tends towards explicit loops and mutating values rather than clean recursion. CLOS is oriented towards objects with mutable state, as well.
Scheme is definitely functional, and yes, it doesn't have pattern matching in it out of the box. I guess it's one of those odd exceptions that strengthen the rules. At the same time, R6RS macros use pattern matching, done very much in tradtional FP style; and, of course, you can trivially implement your own matching construct in both CL and R6RS with macros. In fact, a quick Google search for "Scheme pattern matching" gave me a link to 3 different implementations right away, which seems to hint that it's an oft-requested feature.
Not at all. I'm not sure what you mean by "values" here (I'll touch on that below), but the strict definition of a functional language is "a language that has functions as first-class values". That's all there is to it.
I would define a functional language a language in which all expressions (including defined functions) have no side effects.
Object oriented to me means the introduction of object identity. Object oriented languages often work with collections of objects, that have references between them. Of course it is possible to define a function that queries a collection of objects, but as soon as you introduces means to alter attributes of objects (including references between them) you get serious problems with definining the semantics of your language, because you are introducing side effects. Side effects have a profound implication on things like execution order, which in a purely functional language should not matter (think about lazy evaluation). The only way you can avoid these problems is to let all your functions work on the whole collection of objects. Which means that if you modify one attribute of an object, the whole collection of objects (closed over objects that reference each other) are modified, implying that all objects are modified that belong to that collection. When you reason like this way about a collection of objects, that collection of objects becomes a value.
But often when people talk about object oriented, that put the objects (and not the 'universe', the collection of objects that they belong to) at the center of their attention. For more of my thought, read the articles The Art of Programming and Object-Oriented Considered Harmful.
I've read (Russian) that the following code crashes in runtime:
let comp x y = x > y
let result = comp (new Dictionary<object, object>) (new Dictionary<object, object>)
(I am not an F# expert, I am a Haskell user;)
def fact(x):
return reduce(operator.mul, xrange(2, x+1))
At least that maps an operator on an iter of a list!
I would define a functional language a language in which all expressions (including defined functions) have no side effects.
I see. Well, this isn't the mainstream definition of "functional". What you defined is a "pure" (or "side-effect free") programming language, which, by the way, may or may not be functional. I already gave one example of such - XQuery, which fits your definition to the letter - no side effects whatsoever - but nonetheless it cannot be considered functional if only because it doesn't have first-class functions (no function types, no lambdas...).
Furthermore, Scheme and ML are widely considered functional, and they have mutability and side-effects.
Object oriented to me means the introduction of object identity.
Agreed, but the presence of identity does not imply mutability. It may sound surprising, but nonetheless - look at XQuery again. It does have node identity, which is essentially the same as object identity - some "magical" quantity that nodes possess quite aside from the aggregated value of their attributes and children - but you cannot ever mutate anything in a node. It also has lazy evaluation etc.