<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Here's what I get:<br><br>[michael@localhost ~]$ ghci<br>GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help<br>Loading package ghc-prim ... linking ... done.<br>Loading package integer ... linking ... done.<br>Loading package base ... linking ... done.<br>Prelude> import Prelude hiding ((>>))<br><br><interactive>:1:0: parse error on input `import'<br>Prelude> <br><br>=====<br><br>I was passing seed0 to rollDie and getting back (r1,seed1)<br> passing seed1 to rollDie and getting back (r2,seed2)<br> passing seed2 to rollDie and getting back (r3,seed3)<br><br>Just based on the problem text, I would guess that<br> passing rollDie and seed0 to (>>) I would get back (r3,seed3),<br>losing the
intermediate random numbers r1 and r2 along the way, at<br>least that's what I understood it to say.<br><br>So, I know that next I'm probably going to have to do something to <br>remedy that, but I haven't gotten to that next step yet. What is unsugar?<br><br>Thanks in advance for your patience.<br><br>Michael<br><br><br>--- On <b>Wed, 4/22/09, Dan Weston <i><westondan@imageworks.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Dan Weston <westondan@imageworks.com><br>Subject: Re: [Haskell-cafe] Overriding a Prelude function?<br>To: "Ross Mellgren" <rmm-haskell@z.odi.ac><br>Cc: "michael rice" <nowgate@yahoo.com>, "haskell-cafe@haskell.org" <haskell-cafe@haskell.org><br>Date: Wednesday, April 22, 2009, 12:37 PM<br><br><div class="plainMail">Be aware that the do unsugars to (Prelude.>>), not your (>>), even if you hide
(Prelude.>>):<br><br>import Prelude hiding ((>>))<br>m >> f = error "Call me!"<br>main = putStrLn . show $ do [3,4]<br> [5]<br><br>The desugaring of the do { [3,4]; [5] } is (Prelude.>>) [3,4] [5] = [5,5], whereas you might have hoped for [3,4] >> [5] = error "Call me!"<br><br>Dan<br><br>Ross Mellgren wrote:<br>> I think<br>> <br>> import Prelude hiding ((>>))<br>> <br>> does that.<br>> <br>> -Ross<br>> <br>> On Apr 22, 2009, at 11:44 AM, michael rice wrote:<br>> <br>>> I've been working through this example from: <a href="http://en.wikibooks.org/wiki/Haskell/Understanding_monads" target="_blank">http://en.wikibooks.org/wiki/Haskell/Understanding_monads</a><br>>> <br>>> I understand what they're doing all the way up to the definition of (>>), which duplicates Prelude
function (>>). To continue following the example, I need to know how to override the Prelude (>>) with the (>>) definition in my file rand.hs.<br>>> <br>>> Michael<br>>> <br>>> ==============<br>>> <br>>> [michael@localhost ~]$ cat rand.hs<br>>> import System.Random<br>>> <br>>> type Seed = Int<br>>> <br>>> randomNext :: Seed -> Seed<br>>> randomNext rand = if newRand > 0 then newRand else newRand + 2147483647<br>>> where newRand = 16807 * lo - 2836 * hi<br>>> (hi,lo) = rand `divMod` 127773<br>>> <br>>> toDieRoll :: Seed -> Int<br>>> toDieRoll seed = (seed `mod` 6) + 1<br>>> <br>>> rollDie :: Seed -> (Int, Seed)<br>>> rollDie seed = ((seed `mod` 6) + 1, randomNext seed)<br>>> <br>>> sumTwoDice :: Seed -> (Int,
Seed)<br>>> sumTwoDice seed0 =<br>>> let (die1, seed1) = rollDie seed0<br>>> (die2, seed2) = rollDie seed1<br>>> in (die1 + die2, seed2)<br>>> <br>>> (>>) m n = \seed0 -><br>>> let (result1, seed1) = m seed0<br>>> (result2, seed2) = n seed1<br>>> in (result2, seed2)<br>>> <br>>> [michael@localhost ~]$<br>>> <br>>> <br>>> _______________________________________________<br>>> Haskell-Cafe mailing list<br>>> <a ymailto="mailto:Haskell-Cafe@haskell.org" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a> <mailto:<a ymailto="mailto:Haskell-Cafe@haskell.org" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a>><br>>> <a
href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>> <br><br></div></blockquote></td></tr></table><br>