06 Mar 2011, 05:42
Generic-user-small

Leo (2 posts)

in looking at the body of the treasureMap function on page 304 (“Building a Monad from Scratch”), I am trying to figure out how to parse the expression:

pos >>==
stagger>>==
stagger>>==
crawl>>==
rtn

how is this parsed by GHC? (right associative or left associative >>==)
Like this(right associative >>==)?

pos >>==
(stagger>>==
(stagger>>==
(crawl>>==
rtn)))

or like this(left associative >>==)?

(((pos >>==
stagger>>==)
stagger>>==)
crawl>>==)
rtn

The first(right-associative) would seem to transform like so:
form0: pos >>== (stagger>>== (stagger>>== (crawl>>== rtn)))
...form1: (stagger>>== (stagger>>== (crawl>>== rtn))) (pos)
...form2 (stagger>>== (crawl>>== rtn)) (stagger (pos))
...form3 (crawl>>== rtn) (stagger (stagger (pos)))
....form4 rtn (crawl (stagger (stagger (pos))))

I think I fudged it a bit to make the parentheses work right. My confusion is, for example, in step :
what does (crawl>>==rtn) mean? This can’t be right since crawl>>==return evaluates to return(crawl). Either I’m missing some sort of function composition operator in my rewriting or my transformation is wrong.

Thanks for your help

06 Mar 2011, 07:12
Generic-user-small

Leo (2 posts)

ok, I can see it’s left associative. Does this look right? I’m unsure how many parentheses to keep around? specifically whether to put an expression like stagger(pos) in parentheses, making it (stagger(pos)).

form 0: (((pos >>== stagger)>>== stagger)>>== crawl)>>== rtn
form 1: (((stagger(position))>>== stagger)>>== crawl)>>== rtn
form 2: ((stagger(stagger(position))))>>== crawl)>>== rtn
form 3: (crawl(stagger(stagger(position))))>>== rtn
form 3: rtn(crawl(stagger(stagger(position))))

  You must be logged in to comment