views:

673

answers:

9

I have been researching and playing with functional programming lately, solely to broaden my thinking about programming, because I find thinking "functionally" difficult.

I have downloaded Glasgow Haskell and experimented with that.

What I am wondering is, what is the best platform for Windows to experiment with FP? I would prefer a JVM based approach, but another post on SO has indicated that a real FP language cannot be implemented on the JVM due to a lack of support for tail recursion. What say you?

EDIT: As I've said, I've experimented a fair bit with Haskell; on the advice of one of the answers I've been reviewing the Scala website. Looking over the Scala examples, the code seems more "familiar" (my background is C and Java), but it seems decidedly more OO/procedural and less functional. A huge advantage of Scala would be that it gives me another language tool to use side by side with Java and could become another arrow in my current professional quiver, as opposed to solely being a learning exercise. When I get further into Scala, will the functional aspects become more predominant, or will I tend to end up just writing OO code with some functional influence? In other words, will Haskell challenge my preconceptions harder and faster than Scala?

+3  A: 

Look at Scala. It targets the JVM, interoperates with Java, and has many state of the art functional programming features.

Doug Currie
Kiwi, in response to your EDIT, I agree with Matthias Benkard's comments about the danger of slipping into an imperative style. If you want to be challenged, Haskell is a very good choice.
Doug Currie
+6  A: 

I recommend PLT Scheme and SICP. The language is so simple that you can get on to the important concepts very quickly.

Glomek
+8  A: 

Check out F#. The CLR has a .tail instruction so you can write F# code with tail calls that don't cause a StackOverflow (the exception, not the web site). Here is an intro video about F# from PDC.

Brian
+2  A: 

I love using Haskell and GHC. GHC includes an interactive interpreter (GHCI) and has wonderfully helpful error messages. Plus Haskell's one of the best examples of a truly functional language, and not too bad to use once you experiment with it a bit. Plus it has an awesome type system.

mipadi
A: 

ever tried Prolog? ... that'll

?- bend(your_mind).
Yes


?- bend(X).
X = your_mind

It gave me a whole new perspective anyway ... plenty info out there

Loopo
this isn't functional programming, i don't think.
Claudiu
Prolog is a logic programming language, related to, but not a functional language.
Software Monkey
+4  A: 

Also look at Clojure.

Hank Gay
Thanks; although Lisp is one of those languages whose basic form just grates on me for some reason.
Software Monkey
Kiwi: I used to think the same way, but after actually giving Common Lisp a serious try, I looked back and thought, “why didn't I do this earlier?” I don't recommend a Lisp as a language in which to learn FP, though (see my answer). Lisp's merits lie elsewhere.
Matthias Benkard
+8  A: 

If you really want to learn how to think in a functional way, Haskell is definitely the right choice. Just about every other language out there lets you slip into an imperative style much too easily. Haskell will force you into a functional mindset. I found this indispensible when learning. (You may certainly be more disciplined than I am, of course, but why push your luck?)

When you're satisfied with what you've learned from Haskell (which will be a lot!), you're set to go out and evaluate more liberal functional languages like Clojure or Scala. Or you can stay with Haskell, whose library situation isn't actually all that bad, either. At that point, it's a question of circumstance and personal preference. But in order to make such a choice, having learned how to think in a “pure” functional way first is, I think, vital.

Matthias Benkard
+3  A: 

In other words, will Haskell challenge my preconceptions harder and faster than Scala?

Yes.

If you really want to learn, get far outside your comfort zone.

Are you really going to use Scala for production code in the next 3 months, anyway?

grettke
+4  A: 

No way is Scala going to bend your mind anywhere near as much as Haskell will. The main reason to choose Scala over Haskell when learning FP is to give yourself a more gentle introduction to the dangerous wilds of monads, functors and higher-order goodness. Scala is great if you're coming from an object-oriented background trying to transition that knowledge into functional-land. It's not so great if you want to just dive head-first into the deep end.

Given what you're asking, I would recommend GHC Haskell. Nothing is going to warp your head quite as much as that. :-) With that said though, I think you should still keep an eye on Scala. There are many aspects of the language which are positively unique, particularly its type system (structural+nominal subtyping == sweet). It's not going to hurt your head quite so much as Haskell, but it will give you an insight into some concepts you may not find anywhere else, particularly the so-called "typeful programming" methodology.

Oh, and to answer the second part of your question (FP vs OO in Scala), I tend to write my code in a functional style within an object-oriented framework. It's a bit difficult to describe, but that's the way it is. Think of it like designing an API from an object-oriented standpoint but implementing everything in a functional style. I keep things immutable and spend a lot of time using higher-order methods, but I do it all within the confines of inheritance and conventional nominal subtyping. Every so often, I'll still write something imperative, but only when it is cleaner to do so than to use the functional style.

Daniel Spiewak