
Functionally Solving Problems With Haskell - hawkharris
http://learnyouahaskell.com/functionally-solving-problems
======
tel
While LYAH is a lot of fun, if you've gotten your feet wet with Haskell for a
while and want to see some really powerful examples of "functionally solving
problems" I cannot recommend more highly Richard Bird's "Pearls of Functional
Algorithm Design"[0].

All of the "Functional Pearls" papers are worth a read, but Bird's book is
such a compressed, convenient, powerful collection of advanced functional
problem solving _style_ that I think anyone interested in "thinking"
functionally should strive to read it.

It's not exactly for the faint of heart, to be clear. Bird's idea is that we
can establish certain mathematical rules which allow us to transform "the
simplest thing which could possibly be correct" to an efficient program
through a series of steps, each one maintaining correctness as an invariant.

[0] [http://www.amazon.com/Pearls-Functional-Algorithm-Design-
Ric...](http://www.amazon.com/Pearls-Functional-Algorithm-Design-
Richard/dp/0521513383)

~~~
sordina
The majority of this book is also highly portable. The techniques can be
applied across languages very easily, although, the Haskell implementations
are very elegant.

~~~
tel
I would say that's true in so far as your language you're porting to has a
preponderance of pure functionality and notions of real mathematical
"variables". Without those it'll be hard to get any semblance of equational
reasoning to work out.

------
abraxasz
I read the book a while back and it is absolutely fantastic. What I understand
about monads, I learnt it from this book (no other exposition of monads ever
made sense to me), and I particularly like his progression functors ->
applicative functors -> monads. I think it's the clearest way to proceed
(certainly helped me a lot anyways)

~~~
coolsunglasses
When I teach Haskell, I like to take a diversion from Applicatives to Monoids
before going to Monads.

Understanding join is pretty valuable for understanding Monads too.

~~~
tel
You can do Applicative -> Alternative and study Alternatives as Monoids of
Applicatives and then lay on the difference between (<*>) and (<>) as
producing a seminearring!

And then go study Monads because why not. They're kind of cool, too.

~~~
coolsunglasses
Actually you just reminded me that I need to explain sums and products in
terms of a seminearring.

------
bsamuels
As a side-note, if you want to get into functional programming but don't want
to make the full leap into "PURE EVERYTHING MUST STAY CLEAN DONT BREAK THE
RULES" world of Haskell, F# is another excellent choice for a beginner
functional lang. You can program in either OOP or functional style, letting
you take your time with the transition.

I also toot F#'s horn because it has an amazing resource for learning how to
use functional style in your programs: [http://fsharpforfunandprofit.com/site-
contents/](http://fsharpforfunandprofit.com/site-contents/)

A few pages on that site did more for me regarding functional programming than
the entirety of LYAH did, and it also has a very nice monad tutorial:
[http://fsharpforfunandprofit.com/posts/computation-
expressio...](http://fsharpforfunandprofit.com/posts/computation-expressions-
intro/)

~~~
stesch
Not everybody uses Windows.

F# is a .NET language.

~~~
Tehnix
Heard about Mono?

[http://fsharp.org/use/mac/](http://fsharp.org/use/mac/)
[http://fsharp.org/use/linux/](http://fsharp.org/use/linux/)

~~~
levosmetalo
Are you serious?

~~~
Tehnix
Care to elaborate on that?

~~~
JadeNB
I suspect that levosmetalo
([https://news.ycombinator.com/item?id=7538317](https://news.ycombinator.com/item?id=7538317))
is referring to the common perception (on whose correctness I cannot comment)
that Mono has considerable drawbacks, a perception to whose existence a quick
Google search will attest
([https://www.google.com/search?q=Mono+drawback](https://www.google.com/search?q=Mono+drawback)).

------
brianmwaters_hn
Did anybody else notice what is written on the upside-down calculator about
1/8 down the page?

~~~
quchen
Stuff like this is all over LYAH, silly hidden unrelated jokes. Read the tree
in the Zipper chapter :-)
[http://learnyouahaskell.com/zippers](http://learnyouahaskell.com/zippers)

~~~
groovy2shoes
Also, be sure to read the tree with a pre-order traversal. In-order and post-
order traversals yield a nonsensical string.

------
dbbolton
If you just want to play around with RPN a bit, I made a simple (regex-based)
RPN calculating Perl script a while back:

[https://github.com/dbb/math-
scripts/blob/master/rpn_calc.pl](https://github.com/dbb/math-
scripts/blob/master/rpn_calc.pl)

------
zmanian
Confused why a random chapter from the wonderful LYAH is on the top of Hacker
News....

~~~
Lambdanaut
Yeah. This is annoying. I mean, I can't give an objective measure as to why
this is a tragedy, but I feel like it is, you know?

Let's just all go through our favorite 3 year old books and post HN articles
about every chapter that strikes our fancy why don't we?

~~~
krick
If it actually strikes your fancy, why not? But I also don't understand why
this specific chapter and what poster wanted to show us really.

~~~
Lambdanaut
I guess that's it. It feels very arbitrary and unfocused, and I question the
specific value. I'd feel awful yelling "karma whore" in a crowded theater
without proper evidence, but if it looks and smells like one...

------
stesch
Oh, I remember. That's where I stopped reading the book.

------
maxyb
The link is a chapter from "Learn You a Haskell for Great Good", which I
recommend a lot if you want to learn Haskell. However, if you click through to
the table of contents, you'll see immediately one of my problems with Haskell
as a language: guess in what chapter you finally get to write hello world?

~~~
judk

        main = print "Hello, world!"
    
    

Is that really interesting enough to rush to?

------
ardz
Another Haskell SPAM.

How can anyone seriously code in a language which introduces new kind of bugs
which cannot be detected by any test until running in production on real data
when it is already too late?

~~~
quchen
I don't understand what you said, but it sounds like FUD.

\- Haskell does not have "a new kind of bugs". It's an ordinary programming
language with ordinary bugs.

\- The bugs you put in your program are not any more or less undetectable
before production compared to unstable than they are in other languages.

~~~
ardz
Telling that king is naked also sounds like FUD.

~~~
quchen
FUD is fear, uncertainty, doubt. I corrected your statement by saying there is
no reason for that particular fear, uncertainty, or doubt. I don't see how
that qualifies as FUD. (I'm leaving this thread now.)

