Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Recursive Let (Tom Poliquin)
   2. Re:  Recursive Let (Brandon S. Allbery KF8NH)
   3.  A Comparison of Haskell and Scheme (Benjamin L.Russell)
   4. Re:  A Comparison of Haskell and Scheme (Albert Krewinkel)
   5.  Re: A Comparison of Haskell and Scheme (Benjamin L.Russell)
   6.  Re: A Comparison of Haskell and Scheme (Benjamin L.Russell)
   7. Re:  A Comparison of Haskell and Scheme (Felipe Lessa)


----------------------------------------------------------------------

Message: 1
Date: Mon, 9 Feb 2009 17:43:03 -0800
From: Tom Poliquin <poliq...@softcomp.com>
Subject: [Haskell-beginners] Recursive Let
To: beginners@haskell.org
Message-ID: <200902091743.03601.poliq...@softcomp.com>
Content-Type: text/plain;  charset="us-ascii"


I'm working on learning arrows.
This has led me to ArrowLoop, which then led me
to trying to understand the following,

> tracePlus b = let (c,d) = (d,b:d) 
>               in c
>
> main = do
>      w <- return $ take 10 $ tracePlus 7
>      print w
>

which yields [7,7,7,7,7,7,7,7,7,7]


My confusion two pronged,

1) How let actually 'recurses'

2) How things get started (since d is undefined).


I have some vague understanding of both issues but
I want to make sure what's *really* going on so I
don't base my Haskell learning experience on a house 
of cards. Help greatly appreciated.

My ramblings

1) How does recursion happen?

Being an ex-Schemer I recalled that let x = 3
get translated into something like

   (lambda (x) ... ) 3

So now there's a function involved. It's clear that b:d is

   (cons b d) 

another function. So with appropriate plumbing
I could see the thing recurses but the Haskell viewpoint
eludes me.

2) How do things get started?

It seems that Haskell could figure out that
'd' is a list. If an uninitialized (undefined?) 
list contains [] then things are reasonably
straightforward ..

tracePlus gets applied to 7

   (b:d) then becomes [7]
   (c,d) then becomes ([],7)
   
   Given there's an infinite loop (stream) then 
   'take' grabs 'c' (an [])  and asks for another.
   Haskell's laziness works for us here.

   (b:d) then becomes [7,7]
   (c,d) then becomes (7,[7,7])

   ...
   ...

This is all fine. The only thing that subconsciously
nags me is that we appear to 'return' each time  which 
would imply that we would leave the closure causing 'd' 
to be undefined again.

I know this isn't true and if I close my eyes, think 
really hard, and recall how streams are implemented 
in Scheme (with a value-promise pair; the closure is
actually passed around) then I can see how this would 
all work.

Back to the undefined list ... if it's *not* an
[] and has something to do with bottom ( _|_ )
then my eyes glaze over and I have to go watch a
Woody Allen movie to reset.

Sorry for the rambling.

I really like Haskell and I have found
it very powerful. 

Any help greatly appreciated.

Thanks,

Tom


------------------------------

Message: 2
Date: Mon, 9 Feb 2009 23:42:23 -0500
From: "Brandon S. Allbery KF8NH" <allb...@ece.cmu.edu>
Subject: Re: [Haskell-beginners] Recursive Let
To: Tom Poliquin <poliq...@softcomp.com>
Cc: beginners@haskell.org
Message-ID: <6a551b70-66c4-4a16-8451-4e6f5b458...@ece.cmu.edu>
Content-Type: text/plain; charset="us-ascii"

On 2009 Feb 9, at 20:43, Tom Poliquin wrote:
> I'm working on learning arrows.
> This has led me to ArrowLoop, which then led me
> to trying to understand the following,
>
>> tracePlus b = let (c,d) = (d,b:d)
>>              in c
>>
>> main = do
>>     w <- return $ take 10 $ tracePlus 7
>>     print w
>
> 1) How does recursion happen?
>
> Being an ex-Schemer I recalled that let x = 3
> get translated into something like
>
>   (lambda (x) ... ) 3
>
> So now there's a function involved. It's clear that b:d is
>
>   (cons b d)
>
> another function. So with appropriate plumbing
> I could see the thing recurses but the Haskell viewpoint
> eludes me.

The trick is that the c and d on both sides of the equal sign are  
identical.  Since this asserts that d = b:d, Haskell repeatedly  
prepends b to d (lazily, so "take 10" halts the recursion).

let (c,d) = (d,b:d) in c         = d
let (c,d) = (b:d,b:b:d) in c     = b:d
let (c,d) = (b:b:d,b:b:b:d) in c = b:b:d
...

As long as something consumes elements from c, that let will continue  
to expand recursively.

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20090209/7e0ecc3d/PGP-0001.bin

------------------------------

Message: 3
Date: Tue, 10 Feb 2009 16:18:45 +0900
From: Benjamin L.Russell <dekudekup...@yahoo.com>
Subject: [Haskell-beginners] A Comparison of Haskell and Scheme
To: beginners@haskell.org
Message-ID: <jq82p4l4jfu1f3qf3dnmq5il524h3tg...@4ax.com>
Content-Type: text/plain; charset=us-ascii

Although somewhat dated (posted on October 24, 2006 4:39 PM, to be
precise), here is an interesting comparison of Haskell and Scheme, by
Mark C. Chu-Carroll, a PhD computer scientist who works as a software
engineer at Google, on his blog, regarding whether someone should
translate Douglas Hofstadter's columns introducing Scheme to replace
the Scheme code with Haskell code:

Good Math, Bad Math : Haskell and Scheme: Which One and Why?
http://scienceblogs.com/goodmath/2006/10/haskell_and_scheme_which_one_a.php

The entry discusses differences in syntax, typing, and semantics, and
makes for interesting reading.  Surprisingly, he states that Haskell
syntax is easier to learn for beginners:

>I've actually taught an introduction to computer class using Scheme, 
>and the syntax was a big problem.
>
>I think that syntactically, Haskell is a better language for beginners. 
>Haskell syntax is very redundant, which is good for people. Compare 
>these two little snippets:
>
>(define (fact n)
>    (if (= n 0)
>        1
>        (* n (fact (- n 1)))))
>
>fact n = if n == 0
>        then 1
>        else n * fact(n-1)
>
>Which is easier to read? And the Haskell can get even easier to read 
>and write using pattern matching:
>
>fact 0 = 1
>fact n = n * fact (n-1)
>
>Try this comparison:
>
>(define (fold init reducer list)
>    (if (eq? list ())
>        init
>        (reducer (car list) (fold init reducer (cdr list)))))
>
>versus:
>
>fold init reducer [] = init
>fold init reducer l:ls =  reducer l (fold init reducer ls)
>
>The difference gets much more obvious with bigger pieces of code. 
>Between the deliberate redundancies in Haskell's syntax, and the way 
>that pattern matching lets you decompose programs, the Haskell is 
>significantly clearer.

This is the first time that I have seen a claim that Scheme syntax was
a big problem compared to Haskell syntax, but his claims make sense.
It makes me wonder whether his students were true beginners....

If his claims are true, though, then we probably need a counterpart to
SICP (see http://mitpress.mit.edu/sicp/) for Haskell.  The closest I
can think of is SOE (see http://www.haskell.org/soe/); any
alternatives?  There's also _The Haskell Road to Logic, Maths and
Programming_ (see http://homepages.cwi.nl/~jve/HR/) and _Real World
Haskell_ (see http://book.realworldhaskell.org/), but the former is
really about using Haskell to learn discrete mathematics and logic,
and the latter is not directed toward computer science majors, so they
don't correspond very closely.  If Haskell is well-suited as a
language for beginners, then there shouldn't be any reason for not
creating a Haskell alternative.

-- Benjamin L. Russell
-- 
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: 4
Date: Tue, 10 Feb 2009 00:30:40 -0800
From: Albert Krewinkel <krewin...@gmx.net>
Subject: Re: [Haskell-beginners] A Comparison of Haskell and Scheme
To: Benjamin L.Russell <dekudekup...@yahoo.com>
Cc: beginners@haskell.org
Message-ID: <m2fximithr....@visnet-80.csl.sri.com>
Content-Type: text/plain; charset=us-ascii

Benjamin L.Russell <dekudekup...@yahoo.com> writes:

> Although somewhat dated (posted on October 24, 2006 4:39 PM, to be
> precise), here is an interesting comparison of Haskell and Scheme, by
> Mark C. Chu-Carroll, a PhD computer scientist who works as a software
> engineer at Google, on his blog, regarding whether someone should
> translate Douglas Hofstadter's columns introducing Scheme to replace
> the Scheme code with Haskell code:
>
> Good Math, Bad Math : Haskell and Scheme: Which One and Why?
> http://scienceblogs.com/goodmath/2006/10/haskell_and_scheme_which_one_a.php
>
> The entry discusses differences in syntax, typing, and semantics, and
> makes for interesting reading.

I've got a question related to comparison of Haskell and Lisp.

I just learned some basics about category theory and therefore started
to learn some Haskell, too.  Currently I'm doing most of my hacking in
lisp (to be precise: the probably unpurest language out there, Common
Lisp), so please excuse my ignorance as I'm try to change this.

Of what I've seen so far, I'm very fascinated by the power and elegance
of Haskell.  I read a few short introductions on Monads, getting a
glimps of easy DSL developing in Haskell.  In Lisp, one would use the
macro system to achive this.  Even though the concepts seem
fundamentally different, I was wondering if there are any parallels?

Also, could someone point me to a gentle introduction to syntax,
semantics and type systems?  I understand that lisp-like macros do not
exist in Haskell since they would break the type system and could give
rise to unclear semantics.  I'd like to understand what's going on, so
pointers to books or tutorials would be highly appreciated.

Thanks
Albert

> Surprisingly, he states that Haskell
> syntax is easier to learn for beginners:
>
>>I've actually taught an introduction to computer class using Scheme, 
>>and the syntax was a big problem.
>>
>>I think that syntactically, Haskell is a better language for beginners. 
>>Haskell syntax is very redundant, which is good for people. Compare 
>>these two little snippets:
>>
>>(define (fact n)
>>    (if (= n 0)
>>        1
>>        (* n (fact (- n 1)))))
>>
>>fact n = if n == 0
>>        then 1
>>        else n * fact(n-1)
>>
>>Which is easier to read? And the Haskell can get even easier to read 
>>and write using pattern matching:
>>
>>fact 0 = 1
>>fact n = n * fact (n-1)
>>
>>Try this comparison:
>>
>>(define (fold init reducer list)
>>    (if (eq? list ())
>>        init
>>        (reducer (car list) (fold init reducer (cdr list)))))
>>
>>versus:
>>
>>fold init reducer [] = init
>>fold init reducer l:ls =  reducer l (fold init reducer ls)
>>
>>The difference gets much more obvious with bigger pieces of code. 
>>Between the deliberate redundancies in Haskell's syntax, and the way 
>>that pattern matching lets you decompose programs, the Haskell is 
>>significantly clearer.
>
> This is the first time that I have seen a claim that Scheme syntax was
> a big problem compared to Haskell syntax, but his claims make sense.
> It makes me wonder whether his students were true beginners....
>
> If his claims are true, though, then we probably need a counterpart to
> SICP (see http://mitpress.mit.edu/sicp/) for Haskell.  The closest I
> can think of is SOE (see http://www.haskell.org/soe/); any
> alternatives?  There's also _The Haskell Road to Logic, Maths and
> Programming_ (see http://homepages.cwi.nl/~jve/HR/) and _Real World
> Haskell_ (see http://book.realworldhaskell.org/), but the former is
> really about using Haskell to learn discrete mathematics and logic,
> and the latter is not directed toward computer science majors, so they
> don't correspond very closely.  If Haskell is well-suited as a
> language for beginners, then there shouldn't be any reason for not
> creating a Haskell alternative.
>
> -- Benjamin L. Russell


------------------------------

Message: 5
Date: Tue, 10 Feb 2009 19:03:31 +0900
From: Benjamin L.Russell <dekudekup...@yahoo.com>
Subject: [Haskell-beginners] Re: A Comparison of Haskell and Scheme
To: beginners@haskell.org
Message-ID: <6qg2p4902o0ufaknthbqccmrs1k4abi...@4ax.com>
Content-Type: text/plain; charset=us-ascii

On Tue, 10 Feb 2009 00:30:40 -0800, Albert Krewinkel
<krewin...@gmx.net> wrote:

>Of what I've seen so far, I'm very fascinated by the power and elegance
>of Haskell.  I read a few short introductions on Monads, getting a
>glimps of easy DSL developing in Haskell.  In Lisp, one would use the
>macro system to achive this.  Even though the concepts seem
>fundamentally different, I was wondering if there are any parallels?

Lisp-style macros enable one to extend Lisp syntax.  They take Lisp
code as input, and return Lisp code as output.  This behavior is
closely related to reflection (see
http://en.wikipedia.org/wiki/Reflection_(computer_science)), in which
a computer program observes and modifies its own structure and
behavior.

In a related thread on Haskell-Cafe (see "[Haskell-cafe] Re: Monad
explanation" at
http://www.haskell.org/pipermail/haskell-cafe/2009-February/055052.html),
I recently asked about reflection in Haskell:

>On Wed, 4 Feb 2009 21:43:04 -0800, Max Rabkin <max.rabkin at gmail.com>
>wrote:
>
>>On Wed, Feb 4, 2009 at 9:38 PM, Benjamin L. Russell
>><DekuDekuplex at yahoo.com> wrote:
>>> Is it possible to write a self-referential function in Haskell that
>>> modifies itself?
>>
>>Is it possible to write *any* kind of function in Haskell that
>>modifies *anything*?
>
>While trying to research this issue, I came across a relevant archived
>thread in Haskell-Cafe, entitled "[Haskell-cafe] haskell and
>reflection," started by Greg Meredith, dated "Tue, 11 Sep 2007
>07:09:22 -0700" (see
>http://www.mail-archive.com/haskell-c...@haskell.org/msg29882.html),
>which at first had me worried.  Specifically, Greg wrote as follows:
>
>>Am i wrong in my assessment that the vast majority of reflective machinery
>>is missing from Haskell? Specifically,
>>
>>   - there is no runtime representation of type available for
>>   programmatic representation
>>   - there is no runtime representation of the type-inferencing or
>>   checking machinery
>>   - there is no runtime representation of the evaluation machinery
>>   - there is no runtime representation of the lexical or parsing
>>   machinery

In fact, Haskell does offer a somewhat similar parallel to macros in
Lisp:  Template Haskell (see
http://www.haskell.org/haskellwiki/Template_Haskell).  To continue:

>>Op 11-sep-2007, om 18:43 heeft Greg Meredith het volgende geschreven:
>>
>>[...]
>>
>>Template Haskell [1] is a system that lets you write programs that get 
>>executed at *compile time*, and that produce parts of the Haskell program 
>>to be compiled by manipulating a representation of the program as structured 
>>data. It's a form of reflection restricted to compile time, if you'd ask me.
>>
>>[...]
>>
>>[1] http://www.haskell.org/haskellwiki/Template_Haskell
>
>According to the site referenced by the above-mentioned link,
>
>>Template Haskell is an extension to Haskell 98 that allows you to do 
>>type-safe 
>>compile-time meta-programming, with Haskell both as the manipulating language 
>>and the language being manipulated.

There is also a related thread on this issue:

Explanation of macros; Haskell macros
http://mail.python.org/pipermail/python-list/2003-October/228339.html

The above-referenced paper also references the following related paper
discussing this topic in more detail:

Template Meta-programming for Haskell
by Tim Sheard and Simon Peyton Jones
http://www.haskell.org/th/papers/meta-haskell.ps

>Also, could someone point me to a gentle introduction to syntax,
>semantics and type systems?  I understand that lisp-like macros do not
>exist in Haskell since they would break the type system and could give
>rise to unclear semantics.  I'd like to understand what's going on, so
>pointers to books or tutorials would be highly appreciated.

One book that is often mentioned in this context is the following:

Types and Programming Languages
by Benjamin C. Pierce
http://www.cis.upenn.edu/~bcpierce/tapl/

Hope this helps....

-- Benjamin L. Russell
-- 
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: 6
Date: Tue, 10 Feb 2009 19:09:13 +0900
From: Benjamin L.Russell <dekudekup...@yahoo.com>
Subject: [Haskell-beginners] Re: A Comparison of Haskell and Scheme
To: beginners@haskell.org
Message-ID: <6ck2p4l8ckiq8rk5ucap4iv488b6ocv...@4ax.com>
Content-Type: text/plain; charset=us-ascii

On Tue, 10 Feb 2009 19:03:31 +0900, Benjamin L.Russell
<dekudekup...@yahoo.com> wrote:

>There is also a related thread on this issue:
>
>Explanation of macros; Haskell macros
>http://mail.python.org/pipermail/python-list/2003-October/228339.html
>
>The above-referenced paper also references the following related paper
>discussing this topic in more detail:
>
>Template Meta-programming for Haskell
>by Tim Sheard and Simon Peyton Jones
>http://www.haskell.org/th/papers/meta-haskell.ps

Correction:  Please substitute "thread" for "paper" in the
above-quoted sentence starting with "The above-referenced paper...."

Apologies.

-- Benjamin L. Russell
-- 
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: 7
Date: Tue, 10 Feb 2009 08:25:55 -0200
From: Felipe Lessa <felipe.le...@gmail.com>
Subject: Re: [Haskell-beginners] A Comparison of Haskell and Scheme
To: "Benjamin L. Russell" <dekudekup...@yahoo.com>
Cc: beginners@haskell.org
Message-ID:
        <c2701f5c0902100225g2ac543a6mb382367fffa95...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Tue, Feb 10, 2009 at 5:18 AM, Benjamin L. Russell
<dekudekup...@yahoo.com> wrote:
> Although somewhat dated (posted on October 24, 2006 4:39 PM, to be
> precise), here is an interesting comparison of Haskell and Scheme, by
> Mark C. Chu-Carroll, a PhD computer scientist who works as a software
> engineer at Google, on his blog, regarding whether someone should
> translate Douglas Hofstadter's columns introducing Scheme to replace
> the Scheme code with Haskell code:

He forgot to tell that Haskell is the best imperative language :).

> The entry discusses differences in syntax, typing, and semantics, and
> makes for interesting reading.  Surprisingly, he states that Haskell
> syntax is easier to learn for beginners:

I don't think that's surprising at all. Haskell's syntax is one of the
bests I've ever used: clean, simple, and yet powerful.

-- 
Felipe.


------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 8, Issue 8
***************************************

Reply via email to