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: Map on Nested Lists (Deniz Dogan)
2. Re: Map on Nested Lists (Stephen Tetley)
3. Re: Map on Nested Lists (Thomas Davie)
4. Re: Map on Nested Lists (Tim Sears)
----------------------------------------------------------------------
Message: 1
Date: Thu, 8 Apr 2010 15:41:03 +0200
From: Deniz Dogan <[email protected]>
Subject: Re: [Haskell-beginners] Map on Nested Lists
To: Ben Derrett <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
2010/4/8 Ben Derrett <[email protected]>:
> Hi,
> I'm trying to write a generalization of the map function that operates on
> nested lists, e.g. [[a]] or [[[a]]]. (It should map all elements of type a
> (not list) with f)
> I was thinking of something along these lines:
> mapN f *list of type [a] (where a is not a list type)* = map f l
> mapN f l = (mapN f (head l)):(mapN f (tail l))
>
> Any suggestions about how to go about this?
> Many thanks,
> Ben
>
I think you should look into generic programming for doing this, e.g.
"Scrap Your Boilerplate". There are (at least) three papers on it[1].
[1]: http://research.microsoft.com/en-us/um/people/simonpj/Papers/hmap/index.htm
--
Deniz Dogan
------------------------------
Message: 2
Date: Thu, 8 Apr 2010 16:34:12 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Map on Nested Lists
To: Thomas Davie <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 8 April 2010 14:37, Thomas Davie <[email protected]> wrote:
> You can't write a single such function to operate on all the different
> types, .... [SNIP]
Hi Bob (?)
I believe Oleg Kiselyov's deepset functor manages it...
http://okmij.org/ftp/Haskell/typecast.html
http://okmij.org/ftp/Haskell/deepest-functor.lhs
PS - is it Bob or Thomas? thanks.
Best wishes
Stephen
------------------------------
Message: 3
Date: Thu, 8 Apr 2010 16:38:31 +0100
From: Thomas Davie <[email protected]>
Subject: Re: [Haskell-beginners] Map on Nested Lists
To: Stephen Tetley <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On 8 Apr 2010, at 16:34, Stephen Tetley wrote:
> On 8 April 2010 14:37, Thomas Davie <[email protected]> wrote:
>> You can't write a single such function to operate on all the different
>> types, .... [SNIP]
>
> Hi Bob (?)
>
> I believe Oleg Kiselyov's deepset functor manages it...
>
> http://okmij.org/ftp/Haskell/typecast.html
> http://okmij.org/ftp/Haskell/deepest-functor.lhs
>
> PS - is it Bob or Thomas? thanks.
Well corrected, and either.
Ta
Bob
------------------------------
Message: 4
Date: Thu, 8 Apr 2010 11:58:41 -0400
From: Tim Sears <[email protected]>
Subject: Re: [Haskell-beginners] Map on Nested Lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
If you don't mind choosing a different data type (always a good
question to ask yourself in haskell) you could simply use your own
nested lists....
data Nested a = One a | Nest [Nested a]
deriving Show
instance Functor Nested where
fmap f (One x) = One (f x)
fmap f (Nest xs) = Nest (map (fmap f) xs)
mapN :: (a -> b) -> Nested a -> Nested b
mapN = fmap
test = fmap (+1) $ Nest [One 1, Nest [ One 2, One 3], One 4 , Nest
[ Nest [One 6]] ]
--yields test = Nest [One 2,Nest [One 3,One 4],One 5,Nest [Nest [One
7]]]
On Apr 8, 2010, at 9:05 AM, [email protected] wrote:
> Re: [Haskell-beginners] Map on Nested Lists
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100408/b6504acc/attachment-0001.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 22, Issue 10
*****************************************