[Haskell-cafe] Operator cheat sheet, and monadic style q

Owen Smith ods94065 at gmail.com
Sat Nov 22 04:31:06 EST 2008


Greetings,

I'm a longtime Haskell-curious programmer who, after a few aborted
attempts at getting started and long nights staring at academic
papers, finally managed to get the bug. I've been pleased with my
progress so far, but a couple of things have bugged me enough to seek
advice from the rest of y'all.

1. Contending with the use of frequently unfamiliar non-alphanumeric
operators has been an uphill battle for me. I think the main reason
for this is that I've had no luck in Googling up their definitions (my
primary approach for dealing with every other unknown in the Haskell
universe) due to their very non-alphanumeric nature. I'm curious if 1)
anyone has compiled a cheat sheet of common operators and their
meanings/modules, in some sort of text-search-friendly format (e.g.
spelling out the operator characters, listing alternate names), or 2)
a better way for searching for these things?

2. There's a lot I need to learn about good Haskell style, especially
coming from a C++ background. Even my experience in Lisp seems to
result in way more parentheses than Haskell coders are comfortable
with. :-) In particular, I'm curious about how people actually use
monadic operators. The following simple forms with the Maybe monad,
for example, appear to be equivalent (hope I and QuickCheck are right
about that!):

foo :: Int -> Maybe Int
bar :: Int -> Maybe Int
baz :: Int -> Maybe Int

baz n = (foo n) >>= bar
baz n = bar =<< (foo n)
baz n = (foo >=> bar) n
baz n = (foo <=< bar) n

and I'm thinking the latter two are more idiomatically written as:

baz = foo >=> bar -- I think this one is my fave, naively speaking
baz = bar <=< foo

Yeah, so "there's more than one way to do it"--though I would never
have known about =<<, >=>, and <=< from looking at the introductory
material I've seen on the subject. What do people here prefer using in
what circumstances? Or is everyone off using do notation or arrows
instead? :-)

Thanks for the help!
-- O


More information about the Haskell-Cafe mailing list