Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Announcement: Real World Haskell (Benjamin L. Russell)
2. Boilerplate Code (Matt Andrew)
3. Re: Boilerplate Code (matthew coolbeth)
4. Re: Boilerplate Code (Brent Yorgey)
5. Re: Boilerplate Code (Ozgur Akgun)
----------------------------------------------------------------------
Message: 1
Date: Tue, 03 Aug 2010 17:44:30 +0900
From: [email protected] (Benjamin L. Russell)
Subject: [Haskell-beginners] Re: Announcement: Real World Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Jeff Greer <[email protected]> writes:
> Hi Ben,There is plenty of room at http://linuxagora.com for new reading
> groups. I'll add it to the list. If you know enough that would be
> interested in the Hutton book, it could be done concurrently.
> We are always open for new ideas.Thanks, Jeff
Thank you.
One issue with reading RWH online is the sheer quantity and length of
comments: Many of the comments contain detailed supplementary
information, but reading through all the comments actually takes far
more time than reading the text, with the result that reading them both
together and practicing all the examples takes hours for a single
chapter.
It would be nice to have some kind of rating system/filter for the
comments (say, similar to that for _Slashdot Apple Stories_ [1]), so
that only comments above a certain rating could be filtered through. I
usually wind up reading all the comments (some of which require
re-reading parts of the text for the context) for each section, and by
the time I am done with them, I usually don't have enough time (or
energy) left for the rest of the chapter until the next sitting.
One reason that I suggested _Programming in Haskell_ is that it takes
less time to read. While I appreciate the opportunity to contribute to
editing RWH through comments, reading them all (and some need to be read
through to determine whether they are significant) in a reading group
with deadlines for reading each chapter can be too exhausting.
-- Benjamin L. Russell
[1] _Slashdot Apple Stories._ Geeknet, Inc., 2010. Web. 3
Aug. 2010. <http://apple.slashdot.org/>.
> Message: 2
> Date: Sun, 01 Aug 2010 02:54:58 +0900
> From: [email protected] (Benjamin L. Russell)
> Subject: [Haskell-beginners] Re: Announcement: Real World Haskell -
> Â Â Â Â Reading Group
> To: mailto:[email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=utf-8
>
> Jeff Greer <mailto:[email protected]> writes:
>
>> Hi Russel,Thanks for the suggestion to start a Haskell Reading Group mail
>> list. At the current time, I can not fit it into my schedul...ÃÂ full time
>> teaching job, gard school, and family....I hope some find the reading group
>> useful.
>
>> -- http://teacherwikiweb.com
>
> My pleasure. Â Incidentally, another great book I would suggest for a
> reading group would be _Programming in Haskell_ [1], by Graham Hutton.
>
> Does anybody have any plans to start a reading group for this book?
>
> -- Benjamin L. Russell
>
> [1] Hutton, Graham. _Programming in Haskell._ Cambridge: Cambridge
> University Press,
> 2007. Print. <http://www.cs.nott.ac.uk/%7Egmh/book.html>.
>
--
Benjamin L. Russell / DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile: +011 81 80-3603-6725
"Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^
------------------------------
Message: 2
Date: Tue, 03 Aug 2010 21:51:45 +1000
From: Matt Andrew <[email protected]>
Subject: [Haskell-beginners] Boilerplate Code
To: [email protected]
Message-ID: <87wrs7lxri.wl%[email protected]>
Content-Type: text/plain; charset=US-ASCII
Hi all,
I am in the process of writing a Scheme interpreter/compiler in Haskell as my
first serious project after learning the basics of Haskell. The goal is to
really get a feel for Haskell. I am trying to accomplish this as much as I can
on my own, but am referring to Jonathan Tang's 'Write Yourself a Scheme in 48
hours' whenever I get really stuck.
I have a question regarding a pattern that I have found within my code for
which I cannot seem to find an abstraction.
I am implementing some of the primitive Scheme type-checker functions with the
following code:
numberP :: SchemeVal -> SchemeVal
numberP (Number _) = Bool True
numberP _ = Bool False
boolP :: SchemeVal -> SchemeVal
boolP (Bool _) = Bool True
boolP _ = Bool False
symbolP :: SchemeVal -> SchemeVal
symbolP (Atom _) = Bool True
symbolP _ = Bool False
This is a pattern that I could easily provide an abstraction for with a Lisp
macro, but I'm having trouble discovering if/how it's possible to do so
elegantly in Haskell. The closest (but obviously incorrect) code to what I'm
trying to accomplish would be:
typeChecker :: SchemeVal -> SchemeVal -> SchemeVal
typeChecker (cons _) (cons2 _) = Bool $ cons == cons2
I understand this code drastically misunderstands how pattern matching works,
but (hopefully) it expresses what I'm trying to accomplish. Anyone have any
suggestions?
I do realise that such an abstraction is barely worth it for the amount of code
it will save, but this exercise is about learning the ins and outs of Haskell.
Appreciate you taking the time to read this,
Matt Andrew
------------------------------
Message: 3
Date: Tue, 3 Aug 2010 08:43:28 -0400
From: matthew coolbeth <[email protected]>
Subject: Re: [Haskell-beginners] Boilerplate Code
To: Matt Andrew <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Perhaps I am misunderstanding your question, but why not just skip defining
these predicates altogether? You could just use pattern matching directly
when you want to check that something is a number, or that it is a symbol,
etc.
On Tue, Aug 3, 2010 at 07:51, Matt Andrew <[email protected]> wrote:
> Hi all,
>
> I am in the process of writing a Scheme interpreter/compiler in Haskell as
> my first serious project after learning the basics of Haskell. The goal is
> to really get a feel for Haskell. I am trying to accomplish this as much as
> I can on my own, but am referring to Jonathan Tang's 'Write Yourself a
> Scheme in 48 hours' whenever I get really stuck.
>
> I have a question regarding a pattern that I have found within my code for
> which I cannot seem to find an abstraction.
>
> I am implementing some of the primitive Scheme type-checker functions with
> the following code:
>
> numberP :: SchemeVal -> SchemeVal
> numberP (Number _) = Bool True
> numberP _ = Bool False
>
> boolP :: SchemeVal -> SchemeVal
> boolP (Bool _) = Bool True
> boolP _ = Bool False
>
> symbolP :: SchemeVal -> SchemeVal
> symbolP (Atom _) = Bool True
> symbolP _ = Bool False
>
> This is a pattern that I could easily provide an abstraction for with a
> Lisp macro, but I'm having trouble discovering if/how it's possible to do so
> elegantly in Haskell. The closest (but obviously incorrect) code to what I'm
> trying to accomplish would be:
>
> typeChecker :: SchemeVal -> SchemeVal -> SchemeVal
> typeChecker (cons _) (cons2 _) = Bool $ cons == cons2
>
> I understand this code drastically misunderstands how pattern matching
> works, but (hopefully) it expresses what I'm trying to accomplish. Anyone
> have any suggestions?
>
> I do realise that such an abstraction is barely worth it for the amount of
> code it will save, but this exercise is about learning the ins and outs of
> Haskell.
>
> Appreciate you taking the time to read this,
>
> Matt Andrew
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
mac
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100803/281a126a/attachment-0001.html
------------------------------
Message: 4
Date: Tue, 3 Aug 2010 14:18:39 +0100
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Boilerplate Code
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Tue, Aug 03, 2010 at 09:51:45PM +1000, Matt Andrew wrote:
> Hi all,
>
> I am in the process of writing a Scheme interpreter/compiler in Haskell as my
> first serious project after learning the basics of Haskell. The goal is to
> really get a feel for Haskell. I am trying to accomplish this as much as I
> can on my own, but am referring to Jonathan Tang's 'Write Yourself a Scheme
> in 48 hours' whenever I get really stuck.
>
> I have a question regarding a pattern that I have found within my code for
> which I cannot seem to find an abstraction.
>
> I am implementing some of the primitive Scheme type-checker functions with
> the following code:
>
> numberP :: SchemeVal -> SchemeVal
> numberP (Number _) = Bool True
> numberP _ = Bool False
>
> boolP :: SchemeVal -> SchemeVal
> boolP (Bool _) = Bool True
> boolP _ = Bool False
>
> symbolP :: SchemeVal -> SchemeVal
> symbolP (Atom _) = Bool True
> symbolP _ = Bool False
>
> This is a pattern that I could easily provide an abstraction for with a Lisp
> macro, but I'm having trouble discovering if/how it's possible to do so
> elegantly in Haskell. The closest (but obviously incorrect) code to what I'm
> trying to accomplish would be:
It isn't really possible to abstract this any further in Haskell.
Constructors are rather magical functions, but they are still
functions, and like other functions cannot be compared for equality
directly. Pattern-matching them is the only sort of equality
comparison you get.
With that said, your intuition to use Lisp macros is a good one.
Haskell has a similar metaprogramming facility called Template
Haskell, which could easily be used to automatically generate these
sorts of functions. Of course, it's a little more complicated than
Lisp macros since Haskell syntax is so much more complex than Lisp's
-- but given that, on the whole it's not so bad. I wouldn't use TH to
generate just the three functions you showed -- but I would certainly
consider it for ten.
-Brent
------------------------------
Message: 5
Date: Tue, 3 Aug 2010 14:22:29 +0100
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] Boilerplate Code
To: Matt Andrew <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
To my understanding, what you want is pattern matching on data constructors.
In the following example,
data Expr = Num Int
| Plus Expr Expr
| Minus Expr Expr
incrementNums :: Expr -> Expr
incrementNums (Num i) = Num (i+1)
incrementNums (Plus i j) = Plus (incrementNums i) (incrementNums j)
incrementNums (Minus i j) = Minus (incrementNums i) (incrementNums j)
incrementNums' :: Expr -> Expr
incrementNums' (Num i) = Num (i+1)
incrementNums' (cons i j) = cons (incrementNums' i) (incrementNums' j)
You want incrementNums' instead of incrementNums.
And that's not possible with this data type. Of course you can always do the
following:
data ExprEnum = Plus | Minus
data Expr = Num Int
| BinExpr ExprEnum Expr Expr
incrementNums :: Expr -> Expr
incrementNums (Num i) = Num (i+1)
incrementNums (BinExpr cons i j) = BinExpr cons (incrementNums i)
(incrementNums j)
Hope this helps. Cheers,
On 3 August 2010 12:51, Matt Andrew <[email protected]> wrote:
> Hi all,
>
> I am in the process of writing a Scheme interpreter/compiler in Haskell as
> my first serious project after learning the basics of Haskell. The goal is
> to really get a feel for Haskell. I am trying to accomplish this as much as
> I can on my own, but am referring to Jonathan Tang's 'Write Yourself a
> Scheme in 48 hours' whenever I get really stuck.
>
> I have a question regarding a pattern that I have found within my code for
> which I cannot seem to find an abstraction.
>
> I am implementing some of the primitive Scheme type-checker functions with
> the following code:
>
> numberP :: SchemeVal -> SchemeVal
> numberP (Number _) = Bool True
> numberP _ = Bool False
>
> boolP :: SchemeVal -> SchemeVal
> boolP (Bool _) = Bool True
> boolP _ = Bool False
>
> symbolP :: SchemeVal -> SchemeVal
> symbolP (Atom _) = Bool True
> symbolP _ = Bool False
>
> This is a pattern that I could easily provide an abstraction for with a
> Lisp macro, but I'm having trouble discovering if/how it's possible to do so
> elegantly in Haskell. The closest (but obviously incorrect) code to what I'm
> trying to accomplish would be:
>
> typeChecker :: SchemeVal -> SchemeVal -> SchemeVal
> typeChecker (cons _) (cons2 _) = Bool $ cons == cons2
>
> I understand this code drastically misunderstands how pattern matching
> works, but (hopefully) it expresses what I'm trying to accomplish. Anyone
> have any suggestions?
>
> I do realise that such an abstraction is barely worth it for the amount of
> code it will save, but this exercise is about learning the ins and outs of
> Haskell.
>
> Appreciate you taking the time to read this,
>
> Matt Andrew
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100803/d92ee067/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 26, Issue 3
****************************************