How can I use functional programming in the real world?

19,435

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#.

Solution 5

I'm currently learning Haskell myself, when you start out learning it, it doesn't seem very intriguing because the learning experience is NOTHING like learning a language like C#, it's a whole new world, but I noticed I could write very very complex expressions in just a few lines of code, when I looked back at the code it was much more concise, it was small and tight. I'm absolutely loving it! You can indeed write real-world programs that will be smaller, easier to maintain, and much more complex then most other languages allow, I vote for you to learn it!!

Good luck.

Share:
19,435

Related videos on Youtube

Brian R. Bondy
Author by

Brian R. Bondy

About me: Founder and lead developer for Brave Software, working on the Brave browser. Formerly a Khan Academy software engineer Mozillian (Mozilla contributor) C++, JavaScript, C, C#, Python, programming for > 20 years Graduate of the University of Waterloo; Married with twins boys, one singleton, and a red tri-colored border collie Past Microsoft MVP for Visual C++ Contributor to various other open source projects like WikiMedia Links: Blog/Personal website; Twitter: @brianbondy; Here is a picture of my pet unicorn:

Updated on May 03, 2020

Comments

  • Brian R. Bondy
    Brian R. Bondy about 4 years

    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?

    • Jason Bunting
      Jason Bunting over 15 years
      Personally, I would look into erlang - but that's me.
    • Brian R. Bondy
      Brian R. Bondy over 15 years
      To clarify a little, I have experience with a few different functional programming languages already, and I know how they work and what their differences are. But this question is specifically: how do I take it to a real -world usage.
    • Admin
      Admin almost 14 years
      possible duplicate of Why functional languages?
  • Brian R. Bondy
    Brian R. Bondy over 15 years
    Then I'll post for you: herdingcode.com/?p=45 :)
  • Friedrich
    Friedrich over 15 years
    I'm waiting for it to get it in print. It seems it will be one of the better books around. I bet it will server the people interested in Haskell better than Practical Ocaml does for Ocaml
  • Paul Nathan
    Paul Nathan over 14 years
  • Daniel
    Daniel about 12 years
    Do you still feel like you "want to stick more and more with C#"? F# offers some interesting features. The biggest boost I've gotten is less typing (which means less friction in the process of expressing solutions in code).
  • Marc Gravell
    Marc Gravell about 12 years
    @Daniel in some ways, even more so ;p The tools I work on may be atypical, though.