<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="'trebuchet ms', sans-serif"><div>
<font class="Apple-style-span" color="#003333" face="'trebuchet ms', sans-serif"><br></font></div>(The instance statement has no body.)</font><div><font class="Apple-style-span" color="#003333" face="'trebuchet ms', sans-serif"><br>
</font></div><div><font class="Apple-style-span" color="#003333" face="'trebuchet ms', sans-serif">Then enter Test at the prompt</font><div><font class="Apple-style-span" color="#003333" face="'trebuchet ms', 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="'trebuchet ms', sans-serif">> Test</font></div>
</blockquote><div style="color: rgb(0, 51, 51); font-family: 'trebuchet ms', sans-serif; "><font class="Apple-style-span" color="#003333" face="'trebuchet ms', sans-serif"><br></font></div><font class="Apple-style-span" color="#003333" face="'trebuchet ms', sans-serif">This bombs GHCi. It can't even be interrupted. It must be shut down and restarted.</font><br>
<div><div><div dir="ltr"><font><font face="'trebuchet ms', 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"><<a href="mailto:beginners-request@haskell.org">beginners-request@haskell.org</a>></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 'help' 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 "Re: Contents of Beginners digest..."<br>
<br>
<br>
Today'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'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 <<a href="mailto:amindfv@gmail.com">amindfv@gmail.com</a>><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>
<<a href="mailto:AANLkTimjA0auRvt8z35BStt604on374Nk4YXUfUVCxzy@mail.gmail.com">AANLkTimjA0auRvt8z35BStt604on374Nk4YXUfUVCxzy@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
><br>
><br>
>><br>
> And the type signature given by ghci is<br>
><br>
>> myLength :: (Num t1) => [t] -> t1<br>
>><br>
><br>
><br>
But why is the signature not written as:<br>
myLength :: [t] -> (Num t1) => t1<br>
or something similar?<br>
<br>
I thought that the Num typeclass being first implied that it was the<br>
function'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 <<a href="mailto:daniel.is.fischer@web.de">daniel.is.fischer@web.de</a>><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: <<a href="mailto:201011122112.48289.daniel.is.fischer@web.de">201011122112.48289.daniel.is.fischer@web.de</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
On Friday 12 November 2010 20:14:25, Tom Murphy wrote:<br>
> > And the type signature given by ghci is<br>
> ><br>
> >> myLength :: (Num t1) => [t] -> t1<br>
><br>
> But why is the signature not written as:<br>
> myLength :: [t] -> (Num t1) => t1<br>
> or something similar?<br>
><br>
> I thought that the Num typeclass being first implied that it was the<br>
> function's first argument.<br>
<br>
A type signature like myLength'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 "=>", 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's a third part, the quantification, but that'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) => [a] -> n<br>
<br>
for all types a and n, if n is an instance of Num, myLength has (can have)<br>
the type [a] -> n.<br>
<br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Fri, 12 Nov 2010 21:38:35 +0000<br>
From: Paul Sargent <<a href="mailto:psarge@gmail.com">psarge@gmail.com</a>><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: <<a href="mailto:6751A8C2-8904-4C73-8846-18C6DD1A01EE@gmail.com">6751A8C2-8904-4C73-8846-18C6DD1A01EE@gmail.com</a>><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 "environment" 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've tended to avoid monad based code (except List and Maybe), but I'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 -> Double -> Double -> Double<br>
f env a b = a * ra + b * g' b<br>
where ra = rateA env<br>
g' = g env<br>
<br>
g :: Env -> Double -> Double<br>
g env b = (valueB env) + b<br>
<br>
Basically I'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 -> [Item] -> [Item]<br>
updateList t xs = map (updateItemToTime t) xs<br>
<br>
updateItemToTime :: Double -> Item -> Item<br>
updateItemToTime = some function which does an incremental calculation for a time slice<br>
<br>
(obviously the code is nonsense, I'm just trying to give a feel of the structures I'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'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 <<a href="mailto:byorgey@seas.upenn.edu">byorgey@seas.upenn.edu</a>><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: <<a href="mailto:20101112221233.GA30754@seas.upenn.edu">20101112221233.GA30754@seas.upenn.edu</a>><br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
On Fri, Nov 12, 2010 at 09:38:35PM +0000, Paul Sargent wrote:<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 "environment" 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've tended to avoid monad based code (except List and Maybe), but I'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 -> Double -> Double -> Double<br>
> f env a b = a * ra + b * g' b<br>
> where ra = rateA env<br>
> g' = g env<br>
><br>
> g :: Env -> Double -> Double<br>
> g env b = (valueB env) + b<br>
><br>
> Basically I'm threading the Env parameter through all the function<br>
> calls that need it. Am I right in saying this sort of stuff is a<br>
> 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 -> Double -> Reader Env Double<br>
f a b = do ra <- asks rateA<br>
g' <- g b<br>
return a * ra + b * g'<br>
<br>
g :: Double -> Reader Env Double<br>
g b = asks valueB >>= \b' -> return (b + b')<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 <^(*)^> asks rateA) <^(+)^> (pure b <^(*)^> g b)<br>
<br>
well... I guess you can decide whether you think that's any better.<br>
At least it's closer to the original.<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 -> [Item] -> [Item]<br>
> updateList t xs = map (updateItemToTime t) xs<br>
><br>
> updateItemToTime :: Double -> Item -> Item<br>
> updateItemToTime = some function which does an incremental calculation for a time slice<br>
><br>
> (obviously the code is nonsense, I'm just trying to give a feel of<br>
> the structures I'm using)<br>
<br>
Yes, this could make use of State.<br>
<br>
><br>
> Then, if I did move the code to these monads, how well do the live<br>
> together? ...and how about functions which use functions in multiple<br>
> 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>
> Basically, I haven't seen the advantage of using the monadic way for<br>
> this code, so what am I missing?<br>
<br>
Not too much, necessarily. For the sorts of simple things it seems<br>
like you'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 <<a href="mailto:llp_yyz@hotmail.com">llp_yyz@hotmail.com</a>><br>
Subject: [Haskell-beginners] (no subject)<br>
To: <<a href="mailto:beginners@haskell.org">beginners@haskell.org</a>>, <<a href="mailto:holidayspecial@primetimeshuttle.com">holidayspecial@primetimeshuttle.com</a>>,<br>
<<a href="mailto:noreply@welcome.skype.com">noreply@welcome.skype.com</a>>, <<a href="mailto:service@paypal.com">service@paypal.com</a>>,<br>
<<a href="mailto:kitchenbath@hgtvnewsletters.com">kitchenbath@hgtvnewsletters.com</a>><br>
Message-ID: <COL121-W8D2305DF070F029B361669A340@phx.gbl><br>
Content-Type: text/plain; charset="iso-8859-1"<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 <<a href="mailto:ckkashyap@gmail.com">ckkashyap@gmail.com</a>><br>
Subject: [haskell-beginners] Ralf Laemmel'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>
<AANLkTim53tVCt4kDYbXDRJN=<a href="mailto:OLwc-iEQRvZzkuej%2BqWG@mail.gmail.com">OLwc-iEQRvZzkuej+qWG@mail.gmail.com</a>><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 (->) 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>