Real world Haskell programming

20,782

Solution 1

When you say "real world" examples you are presumably thinking about problems that are inherently sequential or stateful or do lots of I/O, right?

So, how about games?

Or, what about an X Window Manager, an extensible Emacs clone text editor or an IDE?

Then, there is the book, which even has your question already in the title: Real World Haskell and which is also available for free!

Another thing you might want to look at, is Functional Reactive Programming. (It is used in Frag, for example.) The interesting thing about FRP is that it allows you to look at the problem of, say, GUI programming from a very different angle. If you read the GUI chapter in the RWH book, you will see that it talks about how you can write a GUI application just like in C, only better. FRP OTOH allows you to write it in a totally different way that wouldn't even be possible in C.

A lot of times (I'm not saying that this is the case in your question, but it is a recurring pattern) when someone says "but can Haskell be used in the real world", what they are really saying is "I know how to do this in C, and in Haskell I cannot do it in exactly the same way, therefore it must be impossible in Haskell, therefore Haskell is not ready for the real world". But what they are missing out on, is that there might be a totally different and much better way to solve the problem. (It's like saying "Erlang doesn't have threads, therefore it cannot possibly be used to implement concurrent systems.") And FRP is just one example.

Solution 2

For a lightning talk today I have assembled this list of show-case Haskell applications, deliberately excluding anything that only targets programmers:

  • darcs (since 2002, 35 000 loc): Distributed version control system with an innovative focus on changes instead of states.
  • xmonad (since 2007, 30000 loc): Well known tiling window manager with a huge library of layout and other plugins. Made it into the list despite its configuration file being a Haskell file.
  • hledger (since 2007, 9000 loc): Text-file based double-ledger accounting tool, a clone of ledger.
  • Raincat (since 2008, 2000 loc): Platform game with a cat that does not want to get wet.
  • arbtt (since 2009, 2000 loc): My automatic rule-based time tracker. Made it into the list as a shameless plug; probably not that popular. It has now a proper web page contributed by Waldir Pimenta.
  • detexify (since 2010, 500 loc): The back end of the very useful LaTeX character command finder is written in Haskell.
  • git-annex (since 2010, 28 000 loc): Manages your files and their location, a mixture of dropbox and git. Written by famous Joey Hess, who made a living from it via kickstarter He is currently running a second round of funding!
  • Nikki and the Robots (since 2010, 18 000 loc): Platform game with Nikki and, well, his robots. It was produced as a commercial independent game and sold via a pay-what-you-like scheme, but the company unfortunately closed down.
  • hoodle (since 2011, 13 000 loc): A note-taking and PDF annotation software like xournal.
  • Chordify (since 2012, ? loc): Analyses music, e.g. from a YouTube video, and calculates the corresponding guitar chords. Closed software, but supposedly written in Haskell.

(Also featured on my blog, and on the slides of the talk, with nice representative pictures of each program.)

Solution 3

xmonad is event driven (literally). It has a listener loop that wakes up on events, modifying an internal state modelling the X server, which is then rendered to the screen.

http://xmonad.org

Solution 4

I once found this irc bot written in haskell:

http://www.haskell.org/haskellwiki/Roll_your_own_IRC_bot

Solution 5

Here are some links as you requested.

This one explains a lot of things that doesn't 'make sense' to an imperative programmer about Haskell

Haskell Tutorial for C Programmers

This one is a very good easy to follow tutorial

Learn You a Haskell for Great Good

Raytracer written in Haskell

Haskell Raytracer

You can download Glasgow Haskell Compiler from here. GHC

Share:
20,782
raven
Author by

raven

Updated on July 17, 2020

Comments

  • raven
    raven almost 4 years

    Having been an imperative developer for some years now, I had never had the urge to learn functional programming.

    A couple months ago at last I decided to learn Haskell. It's quite a cool language, but I'm puzzled about how an event driven real app would be programmed in such a language. Do you know of a good tutorial about it?

    Note: When I say "real app" I'm not talking of a real world, production ready app. I just mean a little sample app, just to get the grasp of it. I think something like a simplified version of the windows caculator would be great, and then perhaps something a bit more complex.

  • raven
    raven almost 15 years
    Exactly, I have event thought of games myself (I read once a paper from some university which proposed to use a simple game to teach students real world Haskell, but it hasn't much information). I already knew that I can't do things just like in C, and I also knew those things can be done in Haskell (just in another way), but didn't have a clue. That's mainly the reason of my answer. Thanks a lot to you all, guys, you have been really helpful.
  • raven
    raven almost 15 years
    I have read a good part of LYAHFGG. It's very good, and very funny, but I still haven't found anything about inherently sequential problems. Perhaps I must keep on reading.
  • raven
    raven almost 15 years
    Seems like a nice and simple way to start. Thank you!
  • LennyStackOverflow
    LennyStackOverflow almost 13 years
    But also note there is a 'Revisiting "Purely Functional Retrogames"' prog21.dadgum.com/37.html
  • Hi-Angel
    Hi-Angel about 9 years
    I'd add that XMonad is actually a bad example. If you compare that with Awesoe WM (which is using lua), you'd find just how XMonad cumbersome and uncomfortable. I heard that this is a guilt of a bad design of the core, so called StackSet.