Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> For a long time I've been looking for a guide to functional programming, applied to common real-world web examples, but still can't find one.

http://realworldhaskell.org/ (sometimes code is too old to compile)

also good: https://nikita-volkov.github.io/a-taste-of-state-parsers-are...

> database queries

https://www.fpcomplete.com/school/advanced-haskell/persisten...

> performing business logic

Give a more specific example. Preferably with code, and I'll respond with a Haskell/FP equivalent.

> calls to memcached,

    import qualified Database.Memcache.Client as M

    mc <- M.newClient [M.ServerSpec "localhost" 11211 M.NoAuth] M.defaultOptions
    M.set mc "key" "value" 0 0
    v <- M.get mc "key"
More on memcache here: http://hackage.haskell.org/package/memcache

> handling error cases/messages,

http://book.realworldhaskell.org/read/error-handling.html

> validating input

Give an example on input. Depending on complexity I'd most likely use attoparsec or maybe just stuff from the text library.

> outputting data in various formats (JSON, HTML templates, etc.)

JSON: http://hackage.haskell.org/package/aeson

HTML: Not sure about outputting html from a data type's structure, but this might be what you are looking for: http://hackage.haskell.org/package/blaze-html

> how/where does FP help with that?

First I need to know what your definition of FP is. I think it's safe for me to say without knowing your definition that it doesn't help with those specifically as much as it does with tying them all together and having a greater handle on what their behavior/interaction with eachother will be.

> Is FP more a paradigm for computationally intensive programming? Back-end web programming? Front-end?

General purpose.

> I come across "FP is good" all the time, but I've never found any kind of resource to help me understand the tradeoffs between FP and non-FP, where it makes sense to use it and where it doesn't.

That's a shame and I couldn't find really good ones either. To be fair though, such a comparison wouldn't be the easiest to create. I'll add it to my "attempt to blog about" list and we'll see what happens.

In the meantime this might help:

http://phaazon.blogspot.com/2014/02/regular-imperative-state...

> Or any kind of FP tutorial on how to build, for example, a basic web CRUD app.

https://www.fpcomplete.com/school/advanced-haskell/building-...

http://adit.io/posts/2013-04-15-making-a-website-with-haskel...

https://vimeo.com/59109358

https://github.com/ryantrinkle/memoise

https://news.ycombinator.com/item?id=9830431

I'm also in the middle of creating a Haskell version of the Django polls tutorial:

https://docs.djangoproject.com/en/1.8/intro/tutorial01/



Thanks for all those links, that looks super-useful. I'll make my way through them and maybe all this will finally click. Much appreciated!

(And to all the other replies/links as well, I can't edit my original comment anymore and don't want to take up space with extra comments. But all very appreciated!)


No problem. You can also find my email in my profile. Feel free to email me with specific questions. I'm interested in helping people see how Haskell applies or finding cases where it doesn't apply to their real world use cases.

I also have a few semi-useful things on my blog currently so I'll go ahead and put that in my profile as well.

EDIT: Additionally, if you experiment with Haskell be sure to use Stack[0] instead of cabal to avoid potential headaches. The Stack wiki[1] was a useful but easily overlooked resource for me as well.

0: https://github.com/commercialhaskell/stack

1: https://github.com/commercialhaskell/stack/wiki




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: