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. Design Question: fmap with two lists
([email protected])
2. Re: Performance of parallel mergesort (Jon Harrop)
3. Re: Design Question: fmap with two lists (Maciej Piechotka)
4. Finding the height of a simple binary tree (Matt Young)
5. Re: Finding the height of a simple binary tree (Rahul Kapoor)
6. Re: Finding the height of a simple binary tree
(Krzysztof Skrz?tnicki)
7. Re: Finding the height of a simple binary tree
(Krzysztof Skrz?tnicki)
----------------------------------------------------------------------
Message: 1
Date: Thu, 24 Dec 2009 22:21:56 +0000
From: [email protected]
Subject: [Haskell-beginners] Design Question: fmap with two lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I have a class that is basically:
data TwoLists = TL {doubleList :: [Double], intList :: [Int]}
Almost all of the operations of this type map, fold, etc on one of the
lists or the other, and then return a new instance of the type. So I am
implementing to functions dFmap, and iFmap. I actually would like all of
the list functions, but I don't want to reimplement them.
So my question is, what is the haskell way of handling a type like this. Is
there some sort of TwoTypeTraversable I should be deriving from? Essential
is there a Haskell idiom for this situation.
-Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091224/3a3bc1d9/attachment-0001.html
------------------------------
Message: 2
Date: Fri, 25 Dec 2009 00:43:31 +0000
From: Jon Harrop <[email protected]>
Subject: Re: [Haskell-beginners] Performance of parallel mergesort
To: Chadda? Fouch? <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On Thursday 24 December 2009 13:24:30 you wrote:
> ** As you pointed the initial code he chose doesn't parallelize very
> well basically
I Googled for "parallel mergesort haskell" and found that code in lecture
notes by an associate university professor who has pages of published papers
on his specialist topic of parallel programming in Haskell. I had no idea it
was bad code.
> ** He tried to compile it with GHC 6.8 which was an important step
> towards better internals to handle parallelism in GHC but was also a
> time of big upheaval in this field and so not as stable as one could
> wish.
I didn't know that.
> ** He then installed GHC 6.10 and did not even clean up his previous
> compilations attempts before declaring that it didn't work (the error
> message he cited is usually observed when GHC encounters an interface
> file created by a previous version of GHC or on another architecture)
> at all without testing on some other clean sources.
Looks like 6.12 fixed that problem.
> ** He then apparently decided that using a binary package for the 6.12
> version was beneath its dignity and went on to install it from source
> (generally not recommended except for GHC developers that needs to
> work on the code or for port to unusual architectures)
I had no idea that building GHC from source was such a big deal. I'll use the
binaries.
> and claimed
> that there was a "circularity problem" since its 6.10 could not
> compile it (which it obviously could, as he discovered and qualified
> as "miraculous", not even considering that he had a working 6.8
> before).
The circularity problem is that the GHC and Haskell Platform download pages
both say that you must install the other first:
"Stop! For most users, we recommend installing the Haskell Platform instead
of GHC." -
http://www.haskell.org/ghc/download_ghc_6_12_1.html
"You only need GHC installed to get started:" -
http://hackage.haskell.org/platform/
I wasn't sure how to proceed so I guess and apparently got it wrong.
--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e
------------------------------
Message: 3
Date: Fri, 25 Dec 2009 01:48:25 +0100
From: Maciej Piechotka <[email protected]>
Subject: [Haskell-beginners] Re: Design Question: fmap with two lists
To: [email protected]
Message-ID: <1261702105.5686.48.ca...@picard>
Content-Type: text/plain; charset="UTF-8"
On Thu, 2009-12-24 at 22:21 +0000, [email protected] wrote:
> I have a class that is basically:
>
Hmm. Class in haskell means something similar to interface in OOP. Yes
it is confusing.
> data TwoLists = TL {doubleList :: [Double], intList :: [Int]}
>
> Almost all of the operations of this type map, fold, etc on one of the
> lists or the other, and then return a new instance of the type.
It may be my level of English bit I cannot understend this sentence.
> So I am implementing to functions dFmap, and iFmap.
What is dFmap and iFmap?
> I actually would like all of the list functions, but I don't want to
> reimplement them.
>
Hmm. If you need to combine the lists I'd suggest zip/zipWith. If simply
map/fold over one then just write (or similar):
foldr f i . doubleList
If you mean if there is class:
class BiFunctor f where
fmap2 :: (a -> c) -> (b -> d) -> f a b -> f c d
fmap2 f g = fmap2b g . fmap2a f
fmap2a :: (a -> c) -> f a b -> f c b
fmap2a f = fmap2 f id
fmap2b :: (b -> d) -> f a b -> f a d
fmap2b = fmap2 id
To write:
data TwoLists a b = TwoLists [a] [b]
instance BiFunctor TwoLists where
fmap2 f g (TwoLists a b) = TwoLists (map f a) (map g b)
then as far as I know - no - but you can always write your own.
Regards
------------------------------
Message: 4
Date: Thu, 24 Dec 2009 19:18:37 -0600
From: Matt Young <[email protected]>
Subject: [Haskell-beginners] Finding the height of a simple binary
tree
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi guys! Just so we are all on the same page, this problem is an
exercise from the end of Chapter 3 in the book Real World Haskell
(#8).
The problem calls for me to write a function to figure out the height
of our user defined binary tree type.
Here is the type:
--chapter3 binary tree recursive type
data Tree a = Node a (Tree a) (Tree a)
| Empty
deriving (Show)
With this type, we'd create a tree with no leaves like: Node "tree"
Empty Empty, and a tree with a single leaf like Node "tree2" = Empty
(Node "leaf" Empty Empty)
Being new to Haskell, I'm not sure how to traverse this binary tree
type that the book has given. No doubt we'll be using some crafty
recursion to get this done. So to summarize what I'd like to know, 1)
what is the best way to figure out the height of this binary tree type
that I have, or rather any binary tree in general? 2) How do I
translate that into Haskell code.
Verbose explanations are appreciated.
Thanks guys!
--
-Matthew
------------------------------
Message: 5
Date: Thu, 24 Dec 2009 20:34:35 -0500
From: Rahul Kapoor <[email protected]>
Subject: Re: [Haskell-beginners] Finding the height of a simple binary
tree
To: Matt Young <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
See if this case analysis helps:
Height of the Empty Node is zero.
Height of a non empty node is = 1 + (the greater height of its 2 sub trees)
The function max gives you the greater of two values.
HTH
Rahul
On Thu, Dec 24, 2009 at 8:18 PM, Matt Young <[email protected]> wrote:
> Hi guys! Just so we are all on the same page, this problem is an
> exercise from the end of Chapter 3 in the book Real World Haskell
> (#8).
>
> The problem calls for me to write a function to figure out the height
> of our user defined binary tree type.
> Here is the type:
> --chapter3 binary tree recursive type
> data Tree a = Node a (Tree a) (Tree a)
> | Empty
> deriving (Show)
> With this type, we'd create a tree with no leaves like: Node "tree"
> Empty Empty, and a tree with a single leaf like Node "tree2" = Empty
> (Node "leaf" Empty Empty)
>
> Being new to Haskell, I'm not sure how to traverse this binary tree
> type that the book has given. No doubt we'll be using some crafty
> recursion to get this done. So to summarize what I'd like to know, 1)
> what is the best way to figure out the height of this binary tree type
> that I have, or rather any binary tree in general? 2) How do I
> translate that into Haskell code.
>
> Verbose explanations are appreciated.
>
> Thanks guys!
>
>
> --
> -Matthew
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 6
Date: Fri, 25 Dec 2009 02:47:10 +0100
From: Krzysztof Skrz?tnicki <[email protected]>
Subject: Re: [Haskell-beginners] Finding the height of a simple binary
tree
To: Rahul Kapoor <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
The code is also extremely simple:
height Empty = 0 -- Height of the Empty Node is zero.
height (Node t1 t2) = 1 + (max (height t1) (height t2)) -- Height of a non
empty node is = 1 + (the greater height of its 2 sub trees)
Regards
On Fri, Dec 25, 2009 at 02:34, Rahul Kapoor <[email protected]> wrote:
> See if this case analysis helps:
>
> Height of the Empty Node is zero.
> Height of a non empty node is = 1 + (the greater height of its 2 sub trees)
>
> The function max gives you the greater of two values.
>
> HTH
> Rahul
>
> On Thu, Dec 24, 2009 at 8:18 PM, Matt Young <[email protected]> wrote:
> > Hi guys! Just so we are all on the same page, this problem is an
> > exercise from the end of Chapter 3 in the book Real World Haskell
> > (#8).
> >
> > The problem calls for me to write a function to figure out the height
> > of our user defined binary tree type.
> > Here is the type:
> > --chapter3 binary tree recursive type
> > data Tree a = Node a (Tree a) (Tree a)
> > | Empty
> > deriving (Show)
> > With this type, we'd create a tree with no leaves like: Node "tree"
> > Empty Empty, and a tree with a single leaf like Node "tree2" = Empty
> > (Node "leaf" Empty Empty)
> >
> > Being new to Haskell, I'm not sure how to traverse this binary tree
> > type that the book has given. No doubt we'll be using some crafty
> > recursion to get this done. So to summarize what I'd like to know, 1)
> > what is the best way to figure out the height of this binary tree type
> > that I have, or rather any binary tree in general? 2) How do I
> > translate that into Haskell code.
> >
> > Verbose explanations are appreciated.
> >
> > Thanks guys!
> >
> >
> > --
> > -Matthew
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> _______________________________________________
> 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/20091224/4233e852/attachment-0001.html
------------------------------
Message: 7
Date: Fri, 25 Dec 2009 02:48:49 +0100
From: Krzysztof Skrz?tnicki <[email protected]>
Subject: Re: [Haskell-beginners] Finding the height of a simple binary
tree
To: Rahul Kapoor <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
I made a typo: since Node is labeled we need to match against ternary
constructor:
height Empty = 0 -- Height of the Empty Node is zero.
height (Node _ t1 t2) = 1 + (max (height t1) (height t2)) -- Height of a non
empty node is = 1 + (the greater height of its 2 sub trees)
2009/12/25 Krzysztof SkrzÄtnicki <[email protected]>
> The code is also extremely simple:
>
> height Empty = 0 -- Height of the Empty Node is zero.
> height (Node t1 t2) = 1 + (max (height t1) (height t2)) -- Height of a non
> empty node is = 1 + (the greater height of its 2 sub trees)
>
> Regards
>
>
>
> On Fri, Dec 25, 2009 at 02:34, Rahul Kapoor <[email protected]> wrote:
>
>> See if this case analysis helps:
>>
>> Height of the Empty Node is zero.
>> Height of a non empty node is = 1 + (the greater height of its 2 sub
>> trees)
>>
>> The function max gives you the greater of two values.
>>
>> HTH
>> Rahul
>>
>> On Thu, Dec 24, 2009 at 8:18 PM, Matt Young <[email protected]> wrote:
>> > Hi guys! Just so we are all on the same page, this problem is an
>> > exercise from the end of Chapter 3 in the book Real World Haskell
>> > (#8).
>> >
>> > The problem calls for me to write a function to figure out the height
>> > of our user defined binary tree type.
>> > Here is the type:
>> > --chapter3 binary tree recursive type
>> > data Tree a = Node a (Tree a) (Tree a)
>> > | Empty
>> > deriving (Show)
>> > With this type, we'd create a tree with no leaves like: Node "tree"
>> > Empty Empty, and a tree with a single leaf like Node "tree2" = Empty
>> > (Node "leaf" Empty Empty)
>> >
>> > Being new to Haskell, I'm not sure how to traverse this binary tree
>> > type that the book has given. No doubt we'll be using some crafty
>> > recursion to get this done. So to summarize what I'd like to know, 1)
>> > what is the best way to figure out the height of this binary tree type
>> > that I have, or rather any binary tree in general? 2) How do I
>> > translate that into Haskell code.
>> >
>> > Verbose explanations are appreciated.
>> >
>> > Thanks guys!
>> >
>> >
>> > --
>> > -Matthew
>> > _______________________________________________
>> > Beginners mailing list
>> > [email protected]
>> > http://www.haskell.org/mailman/listinfo/beginners
>> >
>> _______________________________________________
>> 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/20091224/31a4e839/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 18, Issue 25
*****************************************