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:  removing duplicate tuples (including symmetrical ones)
      (Ozgur Akgun)
   2.  Re: The Data Parallel Haskell example from the   Haskell Wiki
      won't work (Jo?o Paulo Pizani Flor)
   3. Re:  step by step binding recursion (Felipe Lessa)
   4.  ignature for a list of a set length (Martin Tomko)
   5. Re:  ignature for a list of a set length (Ozgur Akgun)
   6. Re:  ignature for a list of a set length (edgar klerks)


----------------------------------------------------------------------

Message: 1
Date: Tue, 28 Sep 2010 11:24:29 +0100
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] removing duplicate tuples (including
        symmetrical ones)
To: [email protected]
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

I'll first try to give you a more understandable syntax. (I hope.)

nubSym :: Ord a => [(a,a)] -> [(a,a)]
nubSym xs = nub (map fix xs)
  where fix (a,b) | a > b     = (b,a)
                  | otherwise = (a,b)

The two changes above are getting rid of the point-free style[1] and trading
the pattern matching syntax for guards[2].
In the first version the p was for matching with any parameter that didn't
match the first definition. You may want to have a look at how pattern
matching in Haskell works. (Well, you can find lots of resources about this
one but I would have a look at [3])

[1] http://www.haskell.org/haskellwiki/Pointfree
[2] http://en.wikibooks.org/wiki/Haskell/Control_structures#Guards
[3] http://learnyouahaskell.com/syntax-in-functions

happy hacking! :)

On 28 September 2010 11:14, Martin Tomko <[email protected]> wrote:

>  Hi Ozgur,
> well, I am getting a list of tuples from a previous function, and they
> relate to edges in graphs, so I am not too keen to change that, although
> that could be possible. But I never worked with sets in Haskell, so will
> have to study.
>
> Regarding your suggestion - I have to study it, it is a bit advanced.
> First, I see there is no paramter to nubSym  - I have never used that
> syntax, shouldn't there be something like nymSym (x:xs) or so?
> Second, obviously there is a local function, fix. I understand this: fix
> (a,b) | a > b = (b,a)
> but I am not sure how to interpret this:
> fix p = p. Where does p come from? How does haskell know that it relates to
> (a,b), or the x as parameter?
>
> Just asking for clarification ,as I am new to all this.
>
> Thanks
> M.
>
>
> On 9/28/2010 12:05 PM, Ozgur Akgun wrote:
>
> Hi,
>
>  On 28 September 2010 10:33, Martin Tomko <[email protected]> wrote:
>
>> I have a list of (a,a) tuples, and am trying something like nub, but also
>> matching for symmetrical tuples.
>
>
>  You can of course do this. One approach would be to simply 'fix' the
> tuples according to some ordering, and then use standard nub - or a better
> one.
>
>  But to me, the real question is this: If the order of your tuples to
> don't matter, do you actually need tuples? There are other types in which
> the order of the elements in a container does not change the meaning; such
> as a set. You may want to use a Set from Data.Set, or you can define a pair
> type in which ordering doesn't matter. It will end up being a cardinality
> restricted set type though.
>
>  If you just want to get it working, here is some code for the first
> option:
>
>  nubSym :: Ord a => [(a,a)] -> [(a,a)]
> nubSym = nub . map fix
>   where fix (a,b) | a > b = (b,a)
>         fix p = p
>
>  Cheers,
> Ozgur
>
>
>
>


-- 
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100928/7061a752/attachment-0001.html

------------------------------

Message: 2
Date: Tue, 28 Sep 2010 08:41:25 -0300
From: Jo?o Paulo Pizani Flor <[email protected]>
Subject: [Haskell-beginners] Re: The Data Parallel Haskell example
        from the        Haskell Wiki won't work
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

Well, it seems that my problem is solved. I copied again the whole example,
this time literally (Ctrl-C, Ctrl-V), and it just worked.

Problem is, I still don't know what went wrong with my previous attempt :P

Anyways, thanks!

João Paulo Pizani Flor
[email protected]
Ciência da Computação - 2007/1
Universidade Federal de Santa Catarina



2010/9/27 João Paulo Pizani Flor <[email protected]>

> Hello dear Haskell People! I'm currently very interested in doing some
> parallel programming in Haskell, specially in using the Data Parallel
> Haskell stuff...
>
> So as a first step I tried to emulate the vector multiply example found in
> the Haskell Wiki:
> http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell#A_simple_example
>
> 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
>
>
> Regards,
>
> João Paulo Pizani Flor
> [email protected]
> Computer Science - 2007/1
> Federal University of Santa Catarina - Brazil
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100928/4e0f4862/attachment-0001.html

------------------------------

Message: 3
Date: Tue, 28 Sep 2010 08:42:01 -0300
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] step by step binding recursion
To: Nehemiah Clark <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

Hello!

You want the GHCi debugger, see [1,2].

[1] http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/ghci-debugger.html
[2] http://www.cs.mu.oz.au/~bjpop/papers/ghci-debug.monad.reader.pdf

Cheers,

--
Felipe.


------------------------------

Message: 4
Date: Tue, 28 Sep 2010 16:07:33 +0200
From: Martin Tomko <[email protected]>
Subject: [Haskell-beginners] ignature for a list of a set length
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

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



------------------------------

Message: 5
Date: Tue, 28 Sep 2010 15:41:38 +0100
From: Ozgur Akgun <[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="utf-8"

Hi,

On 28 September 2010 15:07, Martin Tomko <[email protected]> wrote:

> 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?)


Well if both the producer and the consumer of this value are your own
functions, you can use something other than a list. You can also implement a
length indexed list, or use such an implementation but it will be overkill
for this task, I think.

The two options are either implementing a wrapper type with three fields, or
using a 3-tuple.
I would use a 3-tuple in both the producer and consumer functions.

Best,
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100928/26166427/attachment-0001.html

------------------------------

Message: 6
Date: Tue, 28 Sep 2010 17:04:47 +0200
From: edgar klerks <[email protected]>
Subject: Re: [Haskell-beginners] ignature for a list of a set length
Cc: [email protected], [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

And if that isn't a possibility, you can use pattern matching:

bla (x:y:z:[]) = do something
bla _ = do nothing


On Tue, Sep 28, 2010 at 4:41 PM, Ozgur Akgun <[email protected]> wrote:

> Hi,
>
>
> On 28 September 2010 15:07, Martin Tomko <[email protected]> wrote:
>
>> 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?)
>
>
> Well if both the producer and the consumer of this value are your own
> functions, you can use something other than a list. You can also implement a
> length indexed list, or use such an implementation but it will be overkill
> for this task, I think.
>
> The two options are either implementing a wrapper type with three fields,
> or using a 3-tuple.
> I would use a 3-tuple in both the producer and consumer functions.
>
> Best,
> Ozgur
>
> _______________________________________________
> 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/20100928/fe3561bf/attachment.html

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 27, Issue 60
*****************************************

Reply via email to