tags:

views:

195

answers:

4

I was reading the Guestbook example for Happstack and noticed the >> symbol which I didn't see before in the textbooks I studied to learn Haskell (for instance see line 23). What is it?

Example

I could not find it in Google because it ignores the >> totally (Bing does not but comes up with tons of non-related results).

Thanks!

+6  A: 

Hayoo recognises this kind of operator: http://holumbus.fh-wedel.de/hayoo/hayoo.html

(>>) is like (>>=), in that it sequences two actions, except that it ignores the result from the first one.

Tim Robinson
Why the downvote?
j_random_hacker
Thanks for that link! Very useful. Upvote.
CharlesS
The ultimate fist-fighting championship dukeout: Hoogle vs. Hayoo!
trinithis
http://hayoo.info/ <-- shorter url to remember :)
ephemient
Thanks for the memorable URL! I've been accessing the site via http://hackage.haskell.org.
Tim Robinson
+6  A: 

At the ghci command prompt, you can type:

:info >>

And get a result like:

class Monad m where
...
(>>) :: m a -> m b -> m b
...
        -- Defined in GHC.Base
infixl 1 >>

From there, you can just take a look at the source code to learn more.

And just for the sake of answering your question:

k >> f = k >>= \_ -> f
jrockway
I feel stupid now; I know about the :i (info) command but I come from Java and PHP and still am getting used to using REPL for everything. Thanks
CharlesS
Correct but barely helpful to a Haskell newbie. Why does it exist? What is it useful for? +0.
j_random_hacker
This is enough for me to find out where to search ; I didn't have any clue before.
CharlesS
+2  A: 

I'm no Haskell expert, but >> is an operator that is used for working with monads, which are an unusual feature that (among many other things) enable imperative-style programming in Haskell. There are many tutorials available on monads; here's one good one.

Essentially, a >> b can be read like "do a then do b, and return the result of b". It's similar to the more common bind operator >>=.

j_random_hacker
Answering with "which are difficult-to-understand things" doesn't clarify. It sets the reader up for failure, I think.
Don Stewart
Fair enough. They are now "an unusual feature" instead of being "difficult-to-understand things."
j_random_hacker
It's "an unusual feature" to call a function and pass the result to another function? OK...
jrockway
You're describing either plain composition of functions, which has nothing to do with monads, or a continuation, and yes those are also difficult for those coming from the imperative world to understand. All that aside: what Haskell topic has produced the greatest number of tutorials and newbie guides (often of the form "A Monad Is Like an X")? Why is that?
j_random_hacker
A: 

In do-notation

a >> b >> c >> d

is equivalent to

do a
   b
   c
   d

(and similarly a >>= (b >>= (c >>= d)) is equivalent to

do r1 <- a
   r2 <- b r1
   r3 <- c r2
   d r3
KennyTM