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: Creating beautiful code: can you make this
divide-and-conquer implementation of the "tails" function
beautiful? (David Place)
2. Re: Creating beautiful code: can you make this
divide-and-conquer implementation of the "tails" function
beautiful? (Michael Xavier)
3. Re: Creating beautiful code: can you make this
divide-and-conquer implementation of the "tails" function
beautiful? (aditya siram)
4. Re: Do I understand this well (Lalitha Prasad K)
5. book review? (Ramy Abdel-Azim)
6. Re: book review? (Sunny Basi)
----------------------------------------------------------------------
Message: 1
Date: Mon, 27 Jun 2011 18:39:14 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] Creating beautiful code: can you make
this divide-and-conquer implementation of the "tails" function
beautiful?
To: "Costello, Roger L." <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Jun 27, 2011, at 4:30 PM, Costello, Roger L. wrote:
> Can the function be simplified and made beautiful?
Surely you're teasing us, Dr. Costello.
------------------------------
Message: 2
Date: Mon, 27 Jun 2011 18:16:53 -0700
From: Michael Xavier <[email protected]>
Subject: Re: [Haskell-beginners] Creating beautiful code: can you make
this divide-and-conquer implementation of the "tails" function
beautiful?
To: "Costello, Roger L." <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I'll bite. The source of tails is pretty elegant:
tails :: [a] -> [[a]]tails [] =
[[]]tails xxs@(_:xs) = xxs : tails xs
On Mon, Jun 27, 2011 at 1:30 PM, Costello, Roger L. <[email protected]>wrote:
> Hi Folks,
>
> Below is a divide-and-conquer implementation of the "tails" function.
>
> Notice the two patterns (x:y:xs) and (x:[]). And notice that (x:y:xs) is
> used by the "length" function and again by the "splitAt" function. That
> doesn't seem elegant. Can the function be simplified and made beautiful?
>
> /Roger
>
>
> tails' :: [a] -> [[a]]
> tails' (x:y:xs) = map (++zs) (tails' ys) ++ tails' zs
> where m = length (x:y:xs)
> n = m `div` 2
> (ys,zs) = splitAt n (x:y:xs)
> tails' (x:[]) = [[x]]
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Michael Xavier
http://www.michaelxavier.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110627/8137cf3f/attachment-0001.htm>
------------------------------
Message: 3
Date: Mon, 27 Jun 2011 21:45:32 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Creating beautiful code: can you make
this divide-and-conquer implementation of the "tails" function
beautiful?
To: Michael Xavier <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I think using iterate expresses tails quite elegantly:
tails = iterate tail
But unfortunately "tail" is unsafe and throws an exception on a empty list:
*Main> tails [1,2,3,4]
[[1,2,3,4],[2,3,4],[3,4],[4],[],*** Exception: Prelude.tail: empty list
To make this correct we can do something like:
tails' l = take (length l) (iterate tail l)
-- or the points free version
-- import Control.Arrow
-- tails' = uncurry take . (length &&& iterate tail)
but that evaluates the entire list twice needlessly and is certainly
not as elegant
Seems to me that to do better than the Prelude definition what we
really need is a exception safe tail function so "tails = iterate
tail" works.
-deech
On Mon, Jun 27, 2011 at 8:16 PM, Michael Xavier <[email protected]> wrote:
> I'll bite. The source of tails is pretty elegant:
>
> tails :: [a] -> [[a]]
> tails [] = [[]]
> tails xxs@(_:xs) = xxs : tails xs
>
> On Mon, Jun 27, 2011 at 1:30 PM, Costello, Roger L. <[email protected]>
> wrote:
>>
>> Hi Folks,
>>
>> Below is a divide-and-conquer implementation of the "tails" function.
>>
>> Notice the two patterns (x:y:xs) and (x:[]). And notice that (x:y:xs) is
>> used by the "length" function and again by the "splitAt" function. That
>> doesn't seem elegant. Can the function be simplified and made beautiful?
>>
>> /Roger
>>
>>
>> tails' ? ? ? ? ? ? ? :: ? [a] -> [[a]]
>> tails' (x:y:xs) ? = ? map (++zs) (tails' ys) ++ tails' zs
>> ? ? ? ? ? ? ? ? ? ? ? ? ? where m ? ? ? ?= ?length (x:y:xs)
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? n ? ? ? ? = ?m `div` 2
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(ys,zs) ?= ?splitAt n (x:y:xs)
>> tails' (x:[]) ? ? ?= ? ?[[x]]
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>
>
>
> --
> Michael Xavier
> http://www.michaelxavier.net
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
------------------------------
Message: 4
Date: Tue, 28 Jun 2011 09:00:37 +0530
From: Lalitha Prasad K <[email protected]>
Subject: Re: [Haskell-beginners] Do I understand this well
To: Roelof Wobben <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Mon, Jun 27, 2011 at 10:22 PM, Roelof Wobben <[email protected]> wrote:
>
> Oke
>
>
>
> It worked now.
>
> A bumpy ride to begin something new with.
>
>
>
> Roelof
>
>
>
> ----------------------------------------
> > From: [email protected]
> > Date: Mon, 27 Jun 2011 23:51:45 +0800
> > Subject: Re: [Haskell-beginners] Do I understand this well
> > To: [email protected]
> > CC: [email protected]
> >
> > Top-level bindings are done in ghci with let:
> >
> > let (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
> >
> > On Mon, Jun 27, 2011 at 11:49 PM, Roelof Wobben <[email protected]>
> wrote:
> > >
> > >
> > >
> > > ________________________________
> > >> Date: Mon, 27 Jun 2011 16:14:28 +0100
> > >> Subject: Re: [Haskell-beginners] Do I understand this well
> > >> From: [email protected]
> > >> To: [email protected]
> > >>
> > >> No.
> > >>
> > >> You are onfusing defining a function with using it.
> > >>
> > >>
> > >> addVectors (x1, y1) (x2, y2) = (x1 + x2, y1 + y2)
> > >>
> > >> defines the function addVectors
> > >>
> > >> (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
> > >>
> > >> calls the function, and binds x and y to the components of the result
> > >> (pattern matching).
> > >>
> > >> Alternatively:
> > >>
> > >> fst . addVectors (3.0, 4.5, -3.4, -5.6)
> > >>
> > >> will return the x-compnent of the result (by composing functions)
> > >>
> > >
> > >
> > > Oke,
> > >
> > >
> > >
> > > I understand that I think
> > >
> > > But when I ghci I enter :
> > >
> > >
> > > (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
> > >
> > >
> > >
> > >
> > >
> > > after I made a file with the file defenition.
> > >
> > > I get this error :
> > >
> > >
> > >
> > > :1:7 parse error on input =
> > >
> > >
> > >
> > > So something is not right here.
> > >
> > >
> > >
> > > Roelof
> > >
> > >
> > > _______________________________________________
> > > Beginners mailing list
> > > [email protected]
> > > http://www.haskell.org/mailman/listinfo/beginners
> > >
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
In GHCI it should be
let (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
Lalitha Prasad
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110628/77fcab2c/attachment-0001.htm>
------------------------------
Message: 5
Date: Tue, 28 Jun 2011 00:20:10 -0400
From: Ramy Abdel-Azim <[email protected]>
Subject: [Haskell-beginners] book review?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
has anyone read this book?
[email protected]
There are some mixed reviews on the product page. I'm a mid-level software
engineer. I've only started learning about Functional programming (didn't
even really learn about lisp in college) in the past 12 months. I'm looking
to learn more about functional programming to help me improve as a
programmer generally.
Thanks,
_Ramy
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110628/1fec5dd5/attachment-0001.htm>
------------------------------
Message: 6
Date: Tue, 28 Jun 2011 02:09:47 -0400
From: Sunny Basi <[email protected]>
Subject: Re: [Haskell-beginners] book review?
To: Ramy Abdel-Azim <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I think you accidently pasted the mailing address email rather then the book
title.
A few good books that I know of,
-Real World Haskell
-Pearls of Functional Algorithm Design
-Programming in Haskell
- Sunny
On Tue, Jun 28, 2011 at 12:20 AM, Ramy Abdel-Azim
<[email protected]>wrote:
> has anyone read this book?
> [email protected]
> There are some mixed reviews on the product page. I'm a mid-level software
> engineer. I've only started learning about Functional programming (didn't
> even really learn about lisp in college) in the past 12 months. I'm looking
> to learn more about functional programming to help me improve as a
> programmer generally.
> Thanks,
> _Ramy
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110628/140771d0/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 36, Issue 76
*****************************************