<div dir="ltr"><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif">This looks like a GHCi bug.</font></font></font><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><br></font></font></font></div>

<div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif">Load </font></font></font></div><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><br></font></font></font></div>

<blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>data Test = Test</div></font></font></font></div>

<div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>instance Show Test where  </div></font></font></font></div></blockquote><font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif"><div>

<font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif"><br></font></div>(The instance statement has no body.)</font><div><font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif"><br>

</font></div><div><font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif">Then enter Test at the prompt</font><div><font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif"><br>

</font></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif">&gt; Test</font></div>

</blockquote><div style="color: rgb(0, 51, 51); font-family: &#39;trebuchet ms&#39;, sans-serif; "><font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif"><br></font></div><font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif">This bombs GHCi. It can&#39;t even be interrupted. It must be shut down and restarted.</font><br>

<div><div><div dir="ltr"><font><font face="&#39;trebuchet ms&#39;, sans-serif"><i><font color="#003333"><br>-- Russ</font></i></font></font></div><br>
<br><br><div class="gmail_quote">On Mon, Nov 15, 2010 at 9:00 AM,  <span dir="ltr">&lt;<a href="mailto:beginners-request@haskell.org">beginners-request@haskell.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">

Send Beginners mailing list submissions to<br>
        <a href="mailto:beginners@haskell.org">beginners@haskell.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:beginners-request@haskell.org">beginners-request@haskell.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:beginners-owner@haskell.org">beginners-owner@haskell.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of Beginners digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
   1. Re:  Why the length function I wrote has such a   type<br>
      signature? (Tom Murphy)<br>
   2. Re:  Why the length function I wrote has such a   type<br>
      signature? (Daniel Fischer)<br>
   3.  Rewriting using State and/or Reader? (Paul Sargent)<br>
   4. Re:  Rewriting using State and/or Reader? (Brent Yorgey)<br>
   5.  (no subject) (David Schonberger)<br>
   6.  Ralf Laemmel&#39;s riddle on surviving without the   monad<br>
      transformation library (C K Kashyap)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Fri, 12 Nov 2010 14:14:25 -0500<br>
From: Tom Murphy &lt;<a href="mailto:amindfv@gmail.com">amindfv@gmail.com</a>&gt;<br>
Subject: Re: [Haskell-beginners] Why the length function I wrote has<br>
        such a  type signature?<br>
Cc: <a href="mailto:beginners@haskell.org">beginners@haskell.org</a><br>
Message-ID:<br>
        &lt;<a href="mailto:AANLkTimjA0auRvt8z35BStt604on374Nk4YXUfUVCxzy@mail.gmail.com">AANLkTimjA0auRvt8z35BStt604on374Nk4YXUfUVCxzy@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;<br>
<br>
&gt;<br>
&gt;<br>
&gt;&gt;<br>
&gt; And the type signature given by ghci is<br>
&gt;<br>
&gt;&gt; myLength :: (Num t1) =&gt; [t] -&gt; t1<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
But why is the signature not written as:<br>
myLength :: [t] -&gt; (Num t1) =&gt; t1<br>
or something similar?<br>
<br>
I thought that the Num typeclass being first implied that it was the<br>
function&#39;s first argument.<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://www.haskell.org/pipermail/beginners/attachments/20101112/896c2084/attachment-0001.html" target="_blank">http://www.haskell.org/pipermail/beginners/attachments/20101112/896c2084/attachment-0001.html</a><br>


<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Fri, 12 Nov 2010 21:12:48 +0100<br>
From: Daniel Fischer &lt;<a href="mailto:daniel.is.fischer@web.de">daniel.is.fischer@web.de</a>&gt;<br>
Subject: Re: [Haskell-beginners] Why the length function I wrote has<br>
        such a  type signature?<br>
To: <a href="mailto:beginners@haskell.org">beginners@haskell.org</a><br>
Message-ID: &lt;<a href="mailto:201011122112.48289.daniel.is.fischer@web.de">201011122112.48289.daniel.is.fischer@web.de</a>&gt;<br>
Content-Type: text/plain;  charset=&quot;utf-8&quot;<br>
<br>
On Friday 12 November 2010 20:14:25, Tom Murphy wrote:<br>
&gt; &gt; And the type signature given by ghci is<br>
&gt; &gt;<br>
&gt; &gt;&gt; myLength :: (Num t1) =&gt; [t] -&gt; t1<br>
&gt;<br>
&gt; But why is the signature not written as:<br>
&gt; myLength :: [t] -&gt; (Num t1) =&gt; t1<br>
&gt; or something similar?<br>
&gt;<br>
&gt; I thought that the Num typeclass being first implied that it was the<br>
&gt; function&#39;s first argument.<br>
<br>
A type signature like myLength&#39;s consists of two parts,<br>
- a context; here (Num t1)<br>
- the part giving the type (subject to the constraints in the context).<br>
<br>
The language definition says the context comes first, then &quot;=&gt;&quot;, finally<br>
the type.<br>
If contexts were always written next to the type they apply to, it would<br>
lead to unreadable type signatures and repetition (the same constraint can<br>
apply to several type variables).<br>
Not to mention multi parameter type classes.<br>
<br>
Strictly speaking, there&#39;s a third part, the quantification, but that&#39;s<br>
usually left implicit (explicit foralls require a language extension).<br>
So the full type is<br>
<br>
myLength :: forall a n. (Num n) =&gt; [a] -&gt; n<br>
<br>
for all types a and n, if n is an instance of Num, myLength has (can have)<br>
the type [a] -&gt; n.<br>
<br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Fri, 12 Nov 2010 21:38:35 +0000<br>
From: Paul Sargent &lt;<a href="mailto:psarge@gmail.com">psarge@gmail.com</a>&gt;<br>
Subject: [Haskell-beginners] Rewriting using State and/or Reader?<br>
To: <a href="mailto:beginners@haskell.org">beginners@haskell.org</a><br>
Message-ID: &lt;<a href="mailto:6751A8C2-8904-4C73-8846-18C6DD1A01EE@gmail.com">6751A8C2-8904-4C73-8846-18C6DD1A01EE@gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
Hi,<br>
<br>
My Haskell project has quite a lot of code in it which either:<br>
<br>
a) Uses a set of common values which are stored in an &quot;environment&quot; data type.<br>
b) Takes a set of values, and updates them repetitively.<br>
<br>
Often the same function will do both.<br>
<br>
Up to now I&#39;ve tended to avoid monad based code (except List and Maybe), but I&#39;m thinking that maybe I can simplify some of my code.<br>
<br>
The code for case a) might look something like:<br>
<br>
    data Env = Env {rateA    :: Double,<br>
                    valueB   :: Double} deriving (Show)<br>
<br>
    f :: Env -&gt; Double -&gt; Double -&gt; Double<br>
    f env a b = a * ra + b * g&#39; b<br>
        where ra = rateA env<br>
              g&#39; = g env<br>
<br>
    g :: Env -&gt; Double -&gt; Double<br>
    g env b = (valueB env) + b<br>
<br>
Basically I&#39;m threading the Env parameter through all the function calls that need it. Am I right in saying this sort of stuff is a good candidate for the Reader monad? What do I gain if I do it?<br>
<br>
Similarly am I right in saying that this type of code is a good candidate for State (called repeatedly from some loop somewhere)?<br>
<br>
    updateList :: Double -&gt; [Item] -&gt; [Item]<br>
    updateList t xs = map (updateItemToTime t) xs<br>
<br>
    updateItemToTime :: Double -&gt; Item -&gt; Item<br>
    updateItemToTime = some function which does an incremental calculation for a time slice<br>
<br>
(obviously the code is nonsense, I&#39;m just trying to give a feel of the structures I&#39;m using)<br>
<br>
Then, if I did move the code to these monads, how well do the live together? ...and how about functions which use functions in multiple different state or reader monads?<br>
<br>
Basically, I haven&#39;t seen the advantage of using the monadic way for this code, so what am I missing?<br>
<br>
Thanks<br>
<br>
Paul<br>
<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Fri, 12 Nov 2010 17:12:33 -0500<br>
From: Brent Yorgey &lt;<a href="mailto:byorgey@seas.upenn.edu">byorgey@seas.upenn.edu</a>&gt;<br>
Subject: Re: [Haskell-beginners] Rewriting using State and/or Reader?<br>
To: <a href="mailto:beginners@haskell.org">beginners@haskell.org</a><br>
Message-ID: &lt;<a href="mailto:20101112221233.GA30754@seas.upenn.edu">20101112221233.GA30754@seas.upenn.edu</a>&gt;<br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
On Fri, Nov 12, 2010 at 09:38:35PM +0000, Paul Sargent wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; My Haskell project has quite a lot of code in it which either:<br>
&gt;<br>
&gt; a) Uses a set of common values which are stored in an &quot;environment&quot; data type.<br>
&gt; b) Takes a set of values, and updates them repetitively.<br>
&gt;<br>
&gt; Often the same function will do both.<br>
&gt;<br>
&gt; Up to now I&#39;ve tended to avoid monad based code (except List and Maybe), but I&#39;m thinking that maybe I can simplify some of my code.<br>
&gt;<br>
&gt; The code for case a) might look something like:<br>
&gt;<br>
&gt;     data Env = Env {rateA    :: Double,<br>
&gt;                     valueB   :: Double} deriving (Show)<br>
&gt;<br>
&gt;     f :: Env -&gt; Double -&gt; Double -&gt; Double<br>
&gt;     f env a b = a * ra + b * g&#39; b<br>
&gt;         where ra = rateA env<br>
&gt;               g&#39; = g env<br>
&gt;<br>
&gt;     g :: Env -&gt; Double -&gt; Double<br>
&gt;     g env b = (valueB env) + b<br>
&gt;<br>
&gt; Basically I&#39;m threading the Env parameter through all the function<br>
&gt; calls that need it. Am I right in saying this sort of stuff is a<br>
&gt; good candidate for the Reader monad? What do I gain if I do it?<br>
<br>
Yes, this is a good candidate for Reader.  You gain not having to<br>
thread the environment around everywhere.  Unfortunately, you lose a<br>
bit in syntax.  These particular functions<br>
could be written like this:<br>
<br>
  f :: Double -&gt; Double -&gt; Reader Env Double<br>
  f a b = do ra &lt;- asks rateA<br>
             g&#39; &lt;- g b<br>
             return a * ra + b * g&#39;<br>
<br>
  g :: Double -&gt; Reader Env Double<br>
  g b = asks valueB &gt;&gt;= \b&#39; -&gt; return (b + b&#39;)<br>
<br>
You can make this a little better with Applicative syntax, especially<br>
if you use InfixApplicative<br>
(<a href="http://hackage.haskell.org/package/InfixApplicative" target="_blank">http://hackage.haskell.org/package/InfixApplicative</a>):<br>
<br>
  f a b = (pure a &lt;^(*)^&gt; asks rateA) &lt;^(+)^&gt; (pure b &lt;^(*)^&gt; g b)<br>
<br>
well... I guess you can decide whether you think that&#39;s any better.<br>
At least it&#39;s closer to the original.<br>
<br>
&gt; Similarly am I right in saying that this type of code is a good candidate for State (called repeatedly from some loop somewhere)?<br>
&gt;<br>
&gt;     updateList :: Double -&gt; [Item] -&gt; [Item]<br>
&gt;     updateList t xs = map (updateItemToTime t) xs<br>
&gt;<br>
&gt;     updateItemToTime :: Double -&gt; Item -&gt; Item<br>
&gt;     updateItemToTime = some function which does an incremental calculation for a time slice<br>
&gt;<br>
&gt; (obviously the code is nonsense, I&#39;m just trying to give a feel of<br>
&gt; the structures I&#39;m using)<br>
<br>
Yes, this could make use of State.<br>
<br>
&gt;<br>
&gt; Then, if I did move the code to these monads, how well do the live<br>
&gt; together? ...and how about functions which use functions in multiple<br>
&gt; different state or reader monads?<br>
<br>
There are actually nice ways to make different monads live together,<br>
but it can require some rather complex and abstract machinery.  See<br>
e.g. the Monatron package<br>
(<a href="http://hackage.haskell.org/package/Monatron" target="_blank">http://hackage.haskell.org/package/Monatron</a>) and this paper:<br>
<br>
<a href="http://people.cs.kuleuven.be/~tom.schrijvers/Research/papers/monad_zipper_draft.pdf" target="_blank">http://people.cs.kuleuven.be/~tom.schrijvers/Research/papers/monad_zipper_draft.pdf</a><br>
<br>
&gt; Basically, I haven&#39;t seen the advantage of using the monadic way for<br>
&gt; this code, so what am I missing?<br>
<br>
Not too much, necessarily.  For the sorts of simple things it seems<br>
like you&#39;re doing, I think the syntactic overhead outweighs the<br>
benefits.<br>
<br>
-Brent<br>
<br>
<br>
------------------------------<br>
<br>
Message: 5<br>
Date: Fri, 12 Nov 2010 23:32:32 -0800<br>
From: David Schonberger &lt;<a href="mailto:llp_yyz@hotmail.com">llp_yyz@hotmail.com</a>&gt;<br>
Subject: [Haskell-beginners] (no subject)<br>
To: &lt;<a href="mailto:beginners@haskell.org">beginners@haskell.org</a>&gt;, &lt;<a href="mailto:holidayspecial@primetimeshuttle.com">holidayspecial@primetimeshuttle.com</a>&gt;,<br>
        &lt;<a href="mailto:noreply@welcome.skype.com">noreply@welcome.skype.com</a>&gt;, &lt;<a href="mailto:service@paypal.com">service@paypal.com</a>&gt;,<br>
        &lt;<a href="mailto:kitchenbath@hgtvnewsletters.com">kitchenbath@hgtvnewsletters.com</a>&gt;<br>
Message-ID: &lt;COL121-W8D2305DF070F029B361669A340@phx.gbl&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;<br>
<br>
<a href="http://ungoalperlavita.org/mainlink.html" target="_blank">http://ungoalperlavita.org/mainlink.html</a><br>
<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://www.haskell.org/pipermail/beginners/attachments/20101113/f2effc24/attachment-0001.html" target="_blank">http://www.haskell.org/pipermail/beginners/attachments/20101113/f2effc24/attachment-0001.html</a><br>


<br>
------------------------------<br>
<br>
Message: 6<br>
Date: Mon, 15 Nov 2010 15:27:00 +0530<br>
From: C K Kashyap &lt;<a href="mailto:ckkashyap@gmail.com">ckkashyap@gmail.com</a>&gt;<br>
Subject: [haskell-beginners] Ralf Laemmel&#39;s riddle on surviving<br>
        without the     monad transformation library<br>
To: <a href="mailto:beginners@haskell.org">beginners@haskell.org</a><br>
Message-ID:<br>
        &lt;AANLkTim53tVCt4kDYbXDRJN=<a href="mailto:OLwc-iEQRvZzkuej%2BqWG@mail.gmail.com">OLwc-iEQRvZzkuej+qWG@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=ISO-8859-1<br>
<br>
Hi,<br>
<br>
Can someone provide me the solution to the following riddle that Ralf<br>
asked in his lecture at<br>
<a href="http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Dr-Ralf-Lmmel-Advanced-Functional-Programming-Evolution-of-an-Interpreter" target="_blank">http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Dr-Ralf-Lmmel-Advanced-Functional-Programming-Evolution-of-an-Interpreter</a><br>


<br>
Riddle: define a custom made monad (only involving (-&gt;) and Either<br>
String) to survive without the monad transformation library.<br>
<br>
<br>
--<br>
Regards,<br>
Kashyap<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br>
<br>
End of Beginners Digest, Vol 29, Issue 18<br>
*****************************************<br>
</blockquote></div><br></div></div></div></div>