[Haskell-cafe] Composing functions with runST
p.f.moore at gmail.com
Thu Jan 4 03:53:46 EST 2007
On 1/3/07, Seth Gordon <sethg at ropine.com> wrote:
> David House wrote:
> >> So I can't just tell someone who's just starting to learn Haskell that
> >> "f $ g y" is equivalent to "f (g y)"; I have to say "those two are
> >> *almost always* equivalent, but if you use $ and the compiler complains
> >> about not being able to match the expected and the inferred type and a
> >> type signature in the error message has the word 'forall', try rewriting
> >> that expression without the $ and see if it compiles". Eeeww.
> > Why would someone just starting to learn Haskell be using ST? The
> > canonical tutorial structure is to start with the pure stuff and only
> > introduce the (more complicated!) impure stuff (ST, IORefs, etc.) in
> > an 'advanced techniques' or similar section.
> I (and one other person on this list) ran into this issue when I was
> trying to use takusen to make Haskell talk to a RDBMS. You obviously
> need to learn advanced techniques to *implement* such a thing, but you
> shouldn't need advanced knowledge to *use a library* that happens to use
> higher-rank polymorphic types in its API.
That other person was me, and I agree entirely. I have a little sample
project, using databases and concurrency, which I wanted to rewrite in
Haskell, as a learning exercise. I hit exactly this issue when simply
trying out some sample code, and my reaction was very much one of
irritation, frustration and confusion.
One of the nice things about Haskell, coming to it from an imperative
POV, is that monads can be thought of a little like first-class
composable "statement blocks". When I understood that, I had a real
"hey, that's neat!" reaction.
One of the nasty things about Haskell (at my level of experience) is
that your nice helpful intuitions about monads can break down into
real confusion when you hit complex monads, monad transformers and the
like - *and you hit them quite early in the APIs of some libraries*!
It's not a big deal, but it's a bit offputting for a newcomer.
More information about the Haskell-Cafe