<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">OK, I changed the operator from (>>) to (~>>). When I try to use it I get this:<br><br>[michael@localhost ~]$ ghci rand<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>[1 of 1] Compiling Main ( rand.hs, interpreted )<br>Ok, modules loaded: Main.<br>*Main> rollDie ~>> (rollDie ~>> rollDie)<br><br><interactive>:1:0:<br> No instance for (Show (Seed -> (Int, Seed)))<br> arising from a use of `print' at <interactive>:1:0-32<br> Possible fix:<br> add an instance declaration for (Show (Seed
-> (Int, Seed)))<br> In a stmt of a 'do' expression: print it<br>*Main> <br><br>Michael<br><br><br>--- On <b>Wed, 4/22/09, Luke Palmer <i><lrpalmer@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Luke Palmer <lrpalmer@gmail.com><br>Subject: Re: [Haskell-cafe] Overriding a Prelude function?<br>To: "michael rice" <nowgate@yahoo.com><br>Cc: "Ross Mellgren" <rmm-haskell@z.odi.ac>, "Dan Weston" <westondan@imageworks.com>, "haskell-cafe@haskell.org" <haskell-cafe@haskell.org><br>Date: Wednesday, April 22, 2009, 5:02 PM<br><br><div id="yiv602338219"><div class="gmail_quote">On Wed, Apr 22, 2009 at 1:47 PM, michael rice <span dir="ltr"><<a rel="nofollow" ymailto="mailto:nowgate@yahoo.com" target="_blank" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>></span> wrote:<br><blockquote
class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit; -x-system-font: none;" valign="top">Here's what I get:<br><br>[michael@localhost ~]$ ghci<br>GHCi, version 6.10.1: <a rel="nofollow" target="_blank" href="http://www.haskell.org/ghc/">http://www.haskell.org/ghc/</a> :? 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 ((>>))</td></tr></tbody></table></blockquote>
<div><br></div><div>You know, to avoid this nonsense you could just name the operator something else, like >>~, or ~>>, or $@**!. Operators are just names.</div><div><br></div><div>Luke</div><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit; -x-system-font: none;" valign="top"><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><<a rel="nofollow" ymailto="mailto:westondan@imageworks.com" target="_blank" href="/mc/compose?to=westondan@imageworks.com">westondan@imageworks.com</a>></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">
<br>From: Dan Weston <<a rel="nofollow" ymailto="mailto:westondan@imageworks.com" target="_blank" href="/mc/compose?to=westondan@imageworks.com">westondan@imageworks.com</a>><br>Subject: Re: [Haskell-cafe] Overriding a Prelude function?<br>To: "Ross Mellgren" <<a rel="nofollow" ymailto="mailto:rmm-haskell@z.odi.ac" target="_blank" href="/mc/compose?to=rmm-haskell@z.odi.ac">rmm-haskell@z.odi.ac</a>><br>
Cc: "michael rice" <<a rel="nofollow" ymailto="mailto:nowgate@yahoo.com" target="_blank" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>>, "<a rel="nofollow" ymailto="mailto:haskell-cafe@haskell.org" target="_blank" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a>" <<a rel="nofollow" ymailto="mailto:haskell-cafe@haskell.org" target="_blank" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a>><br>
Date: Wednesday, April 22, 2009, 12:37 PM<br><br><div><div class="im">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></div><div><div></div><div class="h5">> On Apr 22, 2009, at 11:44 AM, michael rice wrote:<br>
> <br>>> I've been working through this example from: <a rel="nofollow" target="_blank" href="http://en.wikibooks.org/wiki/Haskell/Understanding_monads">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></div></div>>> <a rel="nofollow" target="_blank" href="http://mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a> <mailto:<a rel="nofollow" target="_blank" href="http://mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a>><div class="im">
<br>>> <a rel="nofollow" target="_blank" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>> <br><br></div></div></blockquote></td></tr></tbody></table><br>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a rel="nofollow" ymailto="mailto:Haskell-Cafe@haskell.org" target="_blank" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a rel="nofollow" target="_blank" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>
</div></blockquote></td></tr></table><br>