How can I use functional programming in the real world? [closed]
Functional languages are good because they avoid bugs by eliminating state, but also because they can be easily parallelized automatically for you, without you having to worry about the thread count.
As a Win32 developer though, can I use Haskell for some dlls of my application? And if I do, is there a real advantage that would be taken automatically for me? If so what gives me this advantage, the compiler?
Does F# parallelize functions you write across multiple cores and cpu's automatically for you? Would you ever see the thread count in task manager increase?
Basically my question is, how can I start using Haskell in a practical way, and will I really see some benefits if I do?
Solution 1:
It seems like the book Real World Haskell is just what you're looking for. You can read it free online:
http://book.realworldhaskell.org/
Solution 2:
F# does not contain any magic pixie dust that will pass functions off to different CPU's or machines. What F#/Haskell and other functional programming languages do is make it easier for you to write functions that can be processed independent of the thread or CPU they were created on.
I don't feel right posting a link here to a podcast I participate in, seems a little off, but in the Herding Code episode where we talked with Matt Podwysocki we asked the same question and he gave some interesting answers. There are also a lot of good links relating to functional programming in that episode. I found one link titles "Why Functional Programming Matters" That may provide some answers for you.
Solution 3:
This might also be interesting: "Real World Functional Programming"
Examples are in F# and C#, but the theory is fairly generic. From what I've read (pre-release) it is definitely interesting, but so far I think it is making me want to stick more and more with C#, using libraries like Parallel Extensions.
Solution 4:
You didn't mention, but I'm assuming, that you're using C++. One potentially easy way to get into functional is via C++/CLI to F#. C++ contains "magic pixie dust" (called IJW: It Just Works) to allow you to call into and out of managed code. With this, calling F# code is almost as simple as it is from C#.
I've used this in one program (FreeSWITCH), which is written entirely in C/C++. With a single managed C++/CLI (use the /clr switch), it magically transitions into managed code, and from there, I can go load my F# plugins and execute them. To make things even easier for deployment, F# can statically link all its dependencies, so you don't need to deploy the F# runtime files. One other thing that makes CLR code attractive is that you can pass managed code (delegates) to C code, and the runtime automatically makes a thunk for you.
If you decide to go the Haskell way, the feature you'll be looking for is FFI: Foreign Function Interface. However, I don't think it'll give you the same level of integration as C++/CLI with F#.