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: Padding List with Zeros (Lorenzo Isella)
2. Re: Padding List with Zeros (Greg)
3. Re: Padding List with Zeros (Greg)
4. Re: Padding List with Zeros (jean verdier)
----------------------------------------------------------------------
Message: 1
Date: Wed, 15 Sep 2010 09:28:49 +0200
From: Lorenzo Isella <[email protected]>
Subject: Re: [Haskell-beginners] Padding List with Zeros
To: Antoine Latter <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Hi Antoine,
Unfortunately these are really truly lists and not sets (for instance,
the ordering of elements matter and some of them may be repeated).
Lorenzo
On 09/15/2010 01:55 AM, Antoine Latter wrote:
> Are these truly lists, or would you be better suited using Sets, Maps or
> IntMaps?
>
> Then you can use some of the unionWith functions to decide what to
> insert, or you can simply wrap the looking functions to return zero on
> failure.
>
> Antoine
>
> On Sep 14, 2010 6:35 PM, "Lorenzo Isella" <[email protected]
> <mailto:[email protected]>> wrote:
> > Dear All,
> > I still have to find my way with immutable lists and list comprehension.
> > Consider the following lists
> >
> > A=[0,10,20,30,40,50]
> > B=[0,10,50] (i.e. B is a subset of list A; list A is already ordered in
> > increasing order and so is B).
> > C=[2,1,-5] i.e. there is a corresponding element in C for every element
> > in B.
> >
> > Now, I would like to define a new list D having length equal to the
> > length of A. The elements of D in the position of the elements of A in
> > common with B are equal to the corresponding entries in C, whereas the
> > other ones are zero i.e.
> > D=[2,1,0,0,0,-5]. How can I achieve that? The first thought that comes
> > to my mind is to define a list of zeros which I would modify according
> > to my needs, but that is not allowed...
> > Many thanks
> >
> > Lorenzo
> > _______________________________________________
> > Beginners mailing list
> > [email protected] <mailto:[email protected]>
> > http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 2
Date: Wed, 15 Sep 2010 01:07:13 -0700
From: Greg <[email protected]>
Subject: Re: [Haskell-beginners] Padding List with Zeros
To: Lorenzo Isella <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hey Lorenzo--
Here's at least a partial solution to the specific case you describe:
a=[0,10,20,30,40,50]
b=[0,10,50]
c=[2,1,-5]
d [] _ _ = []
d a [] c = d a [0] c
d a b [] = d a b [0]
d a b c | head a == head b = (head c) : d (tail a) (tail b) (tail c)
| otherwise = 0 : d (tail a) b c
main = do
print $ d a b c
I don't know if it will do what you want if the lists aren't perfectly sized as
they are in your example (meaning your example has all the lists expire at
exactly the same iteration). In this example it will pad out to zero to the
size of a.
Someone may come up with a better example, I'm still learning as I go too. I
was just looking for an opportunity to give back to the list.
Cheers--
Greg
On Sep 15, 2010, at 12:28 AM, Lorenzo Isella wrote:
> Hi Antoine,
> Unfortunately these are really truly lists and not sets (for instance, the
> ordering of elements matter and some of them may be repeated).
>
> Lorenzo
>
> On 09/15/2010 01:55 AM, Antoine Latter wrote:
>> Are these truly lists, or would you be better suited using Sets, Maps or
>> IntMaps?
>>
>> Then you can use some of the unionWith functions to decide what to
>> insert, or you can simply wrap the looking functions to return zero on
>> failure.
>>
>
>
>
>> Antoine
>>
>> On Sep 14, 2010 6:35 PM, "Lorenzo Isella" <[email protected]
>> <mailto:[email protected]>> wrote:
>> > Dear All,
>> > I still have to find my way with immutable lists and list comprehension.
>> > Consider the following lists
>> >
>> > A=[0,10,20,30,40,50]
>> > B=[0,10,50] (i.e. B is a subset of list A; list A is already ordered in
>> > increasing order and so is B).
>> > C=[2,1,-5] i.e. there is a corresponding element in C for every element
>> > in B.
>> >
>> > Now, I would like to define a new list D having length equal to the
>> > length of A. The elements of D in the position of the elements of A in
>> > common with B are equal to the corresponding entries in C, whereas the
>> > other ones are zero i.e.
>> > D=[2,1,0,0,0,-5]. How can I achieve that? The first thought that comes
>> > to my mind is to define a list of zeros which I would modify according
>> > to my needs, but that is not allowed...
>> > Many thanks
>> >
>> > Lorenzo
>> > _______________________________________________
>> > Beginners mailing list
>> > [email protected] <mailto:[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/20100915/2562402e/attachment-0001.html
------------------------------
Message: 3
Date: Wed, 15 Sep 2010 01:16:34 -0700
From: Greg <[email protected]>
Subject: Re: [Haskell-beginners] Padding List with Zeros
To: [email protected]
Cc: Lorenzo Isella <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
I'm realizing that this will misbehave if a starts with values less than zero
and a zero appears after b is exhausted. My second definition of d stuffs
zeros into b after it runs dry, which might accidentally match with a if there
are still zeros in a. That can obviously be worked around...
I probably should have chosen different parameter names for d as well to make
it explicit that they are function arguments and not the same a,b,c as defined
earlier. The argument 'a' is mapped to the defined list 'a' when the function
is called inside main...
On Sep 15, 2010, at 1:07 AM, Greg wrote:
> Hey Lorenzo--
>
> Here's at least a partial solution to the specific case you describe:
>
> a=[0,10,20,30,40,50]
> b=[0,10,50]
> c=[2,1,-5]
>
> d [] _ _ = []
> d a [] c = d a [0] c
> d a b [] = d a b [0]
> d a b c | head a == head b = (head c) : d (tail a) (tail b) (tail c)
> | otherwise = 0 : d (tail a) b c
>
> main = do
> print $ d a b c
>
> I don't know if it will do what you want if the lists aren't perfectly sized
> as they are in your example (meaning your example has all the lists expire at
> exactly the same iteration). In this example it will pad out to zero to the
> size of a.
>
> Someone may come up with a better example, I'm still learning as I go too. I
> was just looking for an opportunity to give back to the list.
>
> Cheers--
> Greg
>
>
>
>
> On Sep 15, 2010, at 12:28 AM, Lorenzo Isella wrote:
>
>> Hi Antoine,
>> Unfortunately these are really truly lists and not sets (for instance, the
>> ordering of elements matter and some of them may be repeated).
>>
>> Lorenzo
>>
>> On 09/15/2010 01:55 AM, Antoine Latter wrote:
>>> Are these truly lists, or would you be better suited using Sets, Maps or
>>> IntMaps?
>>>
>>> Then you can use some of the unionWith functions to decide what to
>>> insert, or you can simply wrap the looking functions to return zero on
>>> failure.
>>>
>>
>>
>>
>>> Antoine
>>>
>>> On Sep 14, 2010 6:35 PM, "Lorenzo Isella" <[email protected]
>>> <mailto:[email protected]>> wrote:
>>> > Dear All,
>>> > I still have to find my way with immutable lists and list comprehension.
>>> > Consider the following lists
>>> >
>>> > A=[0,10,20,30,40,50]
>>> > B=[0,10,50] (i.e. B is a subset of list A; list A is already ordered in
>>> > increasing order and so is B).
>>> > C=[2,1,-5] i.e. there is a corresponding element in C for every element
>>> > in B.
>>> >
>>> > Now, I would like to define a new list D having length equal to the
>>> > length of A. The elements of D in the position of the elements of A in
>>> > common with B are equal to the corresponding entries in C, whereas the
>>> > other ones are zero i.e.
>>> > D=[2,1,0,0,0,-5]. How can I achieve that? The first thought that comes
>>> > to my mind is to define a list of zeros which I would modify according
>>> > to my needs, but that is not allowed...
>>> > Many thanks
>>> >
>>> > Lorenzo
>>> > _______________________________________________
>>> > Beginners mailing list
>>> > [email protected] <mailto:[email protected]>
>>> > http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>> _______________________________________________
>> 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/20100915/72165817/attachment-0001.html
------------------------------
Message: 4
Date: Wed, 15 Sep 2010 10:34:56 +0200
From: jean verdier <[email protected]>
Subject: Re: [Haskell-beginners] Padding List with Zeros
To: Lorenzo Isella <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="UTF-8"
list_A = [0,10,20,30,40,50]
list_B = [0,10,50]
list_C = [2,1,-5]
f a b c = g a (zip b c)
g [] _ = []
g (a:as) xs@((b,c):xs')
| a > b = error "b is not a subset of a"
| a == b = c : g as xs'
| a < b = 0 : g as xs
main = do
print (f list_A list_B list_C)
On Wed, 2010-09-15 at 09:28 +0200, Lorenzo Isella wrote:
> Hi Antoine,
> Unfortunately these are really truly lists and not sets (for instance,
> the ordering of elements matter and some of them may be repeated).
>
> Lorenzo
>
> On 09/15/2010 01:55 AM, Antoine Latter wrote:
> > Are these truly lists, or would you be better suited using Sets, Maps or
> > IntMaps?
> >
> > Then you can use some of the unionWith functions to decide what to
> > insert, or you can simply wrap the looking functions to return zero on
> > failure.
> >
>
>
>
> > Antoine
> >
> > On Sep 14, 2010 6:35 PM, "Lorenzo Isella" <[email protected]
> > <mailto:[email protected]>> wrote:
> > > Dear All,
> > > I still have to find my way with immutable lists and list comprehension.
> > > Consider the following lists
> > >
> > > A=[0,10,20,30,40,50]
> > > B=[0,10,50] (i.e. B is a subset of list A; list A is already ordered in
> > > increasing order and so is B).
> > > C=[2,1,-5] i.e. there is a corresponding element in C for every element
> > > in B.
> > >
> > > Now, I would like to define a new list D having length equal to the
> > > length of A. The elements of D in the position of the elements of A in
> > > common with B are equal to the corresponding entries in C, whereas the
> > > other ones are zero i.e.
> > > D=[2,1,0,0,0,-5]. How can I achieve that? The first thought that comes
> > > to my mind is to define a list of zeros which I would modify according
> > > to my needs, but that is not allowed...
> > > Many thanks
> > >
> > > Lorenzo
> > > _______________________________________________
> > > Beginners mailing list
> > > [email protected] <mailto:[email protected]>
> > > http://www.haskell.org/mailman/listinfo/beginners
> >
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 27, Issue 34
*****************************************