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: ignature for a list of a set length (Jonas Almstr?m Dureg?rd)
2. Re: ignature for a list of a set length (edgar klerks)
3. Re: ignature for a list of a set length (Martin Tomko)
4. Re: ignature for a list of a set length (Martin Tomko)
5. Re: ignature for a list of a set length (David Virebayre)
6. Re: The Data Parallel Haskell example from the Haskell Wiki
won't work (Ben Lippmeier)
7. Re: The Data Parallel Haskell example from the Haskell Wiki
won't work (Ben Lippmeier)
----------------------------------------------------------------------
Message: 1
Date: Tue, 28 Sep 2010 17:05:57 +0200
From: Jonas Almstr?m Dureg?rd <[email protected]>
Subject: Re: [Haskell-beginners] ignature for a list of a set length
To: [email protected]
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
A slightly more readable (IMO) version (which won't fail to terminate
on infinite lists):
getTernaryRelationship (l...@[a,b,c]) = ...
getTernaryRelationship _ = error "getTernaryRelationship: not a ternary rel"
You can of course have type (a,a,a) -> (a,a,a) unless your other
functions require lists
/J
On 28 September 2010 16:07, Martin Tomko <[email protected]> wrote:
> Dear all,
> I want to have a function that acts only on lists of length 3 (I have a
> function that filters a list of lists and returns only those of that
> length). I guess I could change them into tuples (is there a way?), but
> anyway.
> Is there a way to specify in the signature that the function should only
> match such lists, or do I have to do pattern mattching in order to exclude
> other possibilities?:
>
> getTernaryRelationship :: [a] -> [a]
> getTernaryRelationship ls = if (length ls /= 3) then error "not a ternary
> rel" else ...
>
> thanks
> Martin
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 2
Date: Tue, 28 Sep 2010 17:20:23 +0200
From: edgar klerks <[email protected]>
Subject: Re: [Haskell-beginners] ignature for a list of a set length
To: Jonas Almstr?m Dureg?rd <[email protected]>
Cc: [email protected], [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I think it is simpler to use the Maybe type for this. If you only search
for ternary relations, you can write a function, which only converts a list
to a 3-tuple if it is of length three and otherwise it returns nothing. Then
with catMaybes :: [Maybe a] -> [a], you can convert it back to a list with
only 3-tuples.
import Data.Maybe
getLengthThree = catMaybes . fmap toTup
where toTup (x:y:z:[]) = Just (x,y,z)
toTup _ = Nothing
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100928/1405128f/attachment-0001.html
------------------------------
Message: 3
Date: Tue, 28 Sep 2010 17:39:50 +0200
From: Martin Tomko <[email protected]>
Subject: Re: [Haskell-beginners] ignature for a list of a set length
To: edgar klerks <[email protected]>
Cc: [email protected], Jonas Almstr?m Dureg?rd
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I like this suggestion, I will give it a go!
thanks, and also for the catMaybes function, I needed something like
that some days ago.
martin
On 9/28/2010 5:20 PM, edgar klerks wrote:
> I think it is simpler to use the Maybe type for this. If you only
> search for ternary relations, you can write a function, which only
> converts a list to a 3-tuple if it is of length three and otherwise it
> returns nothing. Then with catMaybes :: [Maybe a] -> [a], you can
> convert it back to a list with only 3-tuples.
>
> import Data.Maybe
>
> getLengthThree = catMaybes . fmap toTup
> where toTup (x:y:z:[]) = Just (x,y,z)
> toTup _ = Nothing
>
--
Martin Tomko
Postdoctoral Research Assistant
Geographic Information Systems Division
Department of Geography
University of Zurich - Irchel
Winterthurerstr. 190
CH-8057 Zurich, Switzerland
email: [email protected]
site: http://www.geo.uzh.ch/~mtomko
mob: +41-788 629 558
tel: +41-44-6355256
fax: +41-44-6356848
------------------------------
Message: 4
Date: Tue, 28 Sep 2010 17:41:00 +0200
From: Martin Tomko <[email protected]>
Subject: Re: [Haskell-beginners] ignature for a list of a set length
To: Jonas Almstr?m Dureg?rd <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
As responded earlier, I may try the maybes, but I am intrigued by the
l...@[a,b,c] and I cannto find any documentation about it. If you would
not mind, could you enlighten me?
Thanks
Martin
On 9/28/2010 5:05 PM, Jonas Almström Duregård wrote:
> A slightly more readable (IMO) version (which won't fail to terminate
> on infinite lists):
>
> getTernaryRelationship (l...@[a,b,c]) = ...
> getTernaryRelationship _ = error "getTernaryRelationship: not a ternary rel"
>
> You can of course have type (a,a,a) -> (a,a,a) unless your other
> functions require lists
>
> /J
>
> On 28 September 2010 16:07, Martin Tomko<[email protected]> wrote:
>
>> Dear all,
>> I want to have a function that acts only on lists of length 3 (I have a
>> function that filters a list of lists and returns only those of that
>> length). I guess I could change them into tuples (is there a way?), but
>> anyway.
>> Is there a way to specify in the signature that the function should only
>> match such lists, or do I have to do pattern mattching in order to exclude
>> other possibilities?:
>>
>> getTernaryRelationship :: [a] -> [a]
>> getTernaryRelationship ls = if (length ls /= 3) then error "not a ternary
>> rel" else ...
>>
>> thanks
>> Martin
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
--
Martin Tomko
Postdoctoral Research Assistant
Geographic Information Systems Division
Department of Geography
University of Zurich - Irchel
Winterthurerstr. 190
CH-8057 Zurich, Switzerland
email: [email protected]
site: http://www.geo.uzh.ch/~mtomko
mob: +41-788 629 558
tel: +41-44-6355256
fax: +41-44-6356848
------------------------------
Message: 5
Date: Wed, 29 Sep 2010 09:23:25 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] ignature for a list of a set length
To: [email protected]
Cc: [email protected], Jonas Almstr?m Dureg?rd
<[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
2010/9/28 Martin Tomko <[email protected]>:
> As responded earlier, I may try the maybes, but I am intrigued by the
> l...@[a,b,c] Â and I cannto find any documentation about it. If you would not
When pattern matching a list of 3 elements,
- ls is the whole 3-element list
- a is the first element
- b is the second element
- c is the last.
You can use it anytime you need to deconstruct a value, but also have
a name for the value.
Examples
m...@just j
l@(x:xs)
...
> mind, could you enlighten me?
> Thanks
> Martin
>
>
> On 9/28/2010 5:05 PM, Jonas Almström Duregård wrote:
>>
>> A slightly more readable (IMO) version (which won't fail to terminate
>> on infinite lists):
>>
>> getTernaryRelationship (l...@[a,b,c]) = ...
>> getTernaryRelationship _ = error "getTernaryRelationship: not a ternary
>> rel"
>>
>> You can of course have type (a,a,a) -> Â (a,a,a) unless your other
>> functions require lists
>>
>> /J
>>
>> On 28 September 2010 16:07, Martin Tomko<[email protected]> Â wrote:
>>
>>>
>>> Dear all,
>>> I want to have a function that acts only on lists of length 3 (I have a
>>> function that filters a list of lists and returns only those of that
>>> length). I guess I could change them into tuples (is there a way?), but
>>> anyway.
>>> Is there a way to specify in the signature that the function should only
>>> match such lists, or do I have to do pattern mattching in order to
>>> exclude
>>> other possibilities?:
>>>
>>> getTernaryRelationship :: [a] -> Â [a]
>>> getTernaryRelationship ls = if (length ls /= 3) then error "not a ternary
>>> rel" else ...
>>>
>>> thanks
>>> Martin
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>>
>
>
> --
> Martin Tomko
> Postdoctoral Research Assistant
>
> Geographic Information Systems Division
> Department of Geography
> University of Zurich - Irchel
> Winterthurerstr. 190
> CH-8057 Zurich, Switzerland
>
> email: Â [email protected]
> site: Â http://www.geo.uzh.ch/~mtomko
> mob: Â Â +41-788 629 558
> tel: Â Â +41-44-6355256
> fax: Â Â +41-44-6356848
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 6
Date: Wed, 29 Sep 2010 03:25:22 -0400
From: Ben Lippmeier <[email protected]>
Subject: Re: [Haskell-beginners] The Data Parallel Haskell example
from the Haskell Wiki won't work
To: Jo?o Paulo Pizani Flor <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On 27/09/2010, at 10:06 , João Paulo Pizani Flor wrote:
>
> The code I've written (two files) for this example is in the following
> pastebins:
>
> DPHVecMul.hs: http://paste.org/pastebin/view/22899
> Main.hs: http://paste.org/pastebin/view/22900
>
> I've compiled successfully both files and linked them, exactly as described
> in the Wiki. But when I run the resulting executable, the following error
> shows up:
>
> "dotp: Prelude.undefined"
>
> It's seems (from the tests I've done) that the call to the function
> fromPArrayP of the module Data.Parallel.Array.Prelude results always in
> undefined. In fact, I've taken a look at the function definition in the docs,
> and in fact it always returns undefined. It doesn't make ANY SENSE to me :P
>
> Has someone been able to successfully compile and run this example code?? If
> so, what am I doing wrong? Is there some obvious error I'm incurring in? :D
It's because you didn't add {-# OPTIONS -fvectorise #-} when compiling the
DPHVectMul.hs module. The GHC vectoriser rewrites calls to fromPArrayP to the
real implementations in its back-end library, but if the vectoriser doesn't run
you get the default implementation which is just "undefined". I agree its an
atrocious error message. It should have a real one in the head / GHC 7.0
Ben.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100929/d2dda1f0/attachment-0001.html
------------------------------
Message: 7
Date: Wed, 29 Sep 2010 03:27:19 -0400
From: Ben Lippmeier <[email protected]>
Subject: Re: [Haskell-beginners] The Data Parallel Haskell example
from the Haskell Wiki won't work
To: Ben Lippmeier <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
>> Has someone been able to successfully compile and run this example code?? If
>> so, what am I doing wrong? Is there some obvious error I'm incurring in? :D
>
> It's because you didn't add {-# OPTIONS -fvectorise #-} when compiling the
> DPHVectMul.hs module. The GHC vectoriser rewrites calls to fromPArrayP to the
> real implementations in its back-end library, but if the vectoriser doesn't
> run you get the default implementation which is just "undefined". I agree its
> an atrocious error message. It should have a real one in the head / GHC 7.0
You can also add -fvectorise on the command line, but I prefer using the
OPTIONS pragma because it's less easy to forget.
Ben.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 27, Issue 61
*****************************************