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:  Expressing the idea of a group in Haskell (Stephen Tetley)
   2. Re:  Expressing the idea of a group in Haskell
      (Patrick LeBoutillier)
   3. Re:  Expressing the idea of a group in Haskell (Daniel Fischer)
   4.  New Thread: QuickCheck (Patrick Lynch)
   5.  overload a function (Britt Anderson)
   6.  New Thread: QuickCheck (Alexey G)
   7. Re:  overload a function (Karthick Gururaj)
   8. Re:  New Thread: QuickCheck (Patrick Lynch)
   9. Re:  Expressing the idea of a group in Haskell (Brent Yorgey)
  10. Re:  overload a function (Brent Yorgey)


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

Message: 1
Date: Wed, 16 Mar 2011 12:04:45 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Expressing the idea of a group in
        Haskell
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Pragmatically you might want two classes - AdditiveGroup and
MultiplicativeGroup.

There is a lot of work in this area such as the NumericPrelude on
Hackage and Jerzy Karczmarczuk's paper "Functional Programming and
Mathematical Objects" [link below]. Numeric hierarchies expose
problems for Haskell's class system, hence everyone complains about
the Num classes but no-one has been able to fix them.


http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.32.3328



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

Message: 2
Date: Wed, 16 Mar 2011 08:41:25 -0400
From: Patrick LeBoutillier <[email protected]>
Subject: Re: [Haskell-beginners] Expressing the idea of a group in
        Haskell
To: Christian <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi,

Math newbie here: what's the difference between a group and a monoid?

Patrick


On Wed, Mar 16, 2011 at 4:49 AM, Christian <[email protected]> wrote:
> Hello Haskell-Experts!
> I was trying to express the notion of a (mathematical) group
> in Haskell, using type classes, as an exercise.
> If I am not mistaken, a group can be for example the Reals together with
> the multiplication operation and "1" as the neutral element.
> Or, the Reals with addition and "0".
> my first idea was to write something like
>
> ?class Group a where
> ? ...
>
> _but_, I thought, I need to parameterise, so to speak, not only using the
> type "a", but also the group operation.
> How could I do that in Haskell? Is that even possible?
>
> Thanks in advance!
> Christian
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
=====================
Patrick LeBoutillier
Rosem?re, Qu?bec, Canada



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

Message: 3
Date: Wed, 16 Mar 2011 13:58:08 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Expressing the idea of a group in
        Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="iso-8859-1"

On Wednesday 16 March 2011 13:41:25, Patrick LeBoutillier wrote:
> Hi,
> 
> Math newbie here: what's the difference between a group and a monoid?

In a group, there are inverses. A group is a monoid in which every element 
has an inverse.

So, natural numbers with addition: monoid, no inverses for n /= 0
Integers with addition: group



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

Message: 4
Date: Wed, 16 Mar 2011 10:26:46 -0400
From: "Patrick Lynch" <[email protected]>
Subject: [Haskell-beginners] New Thread: QuickCheck
To: <[email protected]>
Message-ID: <660764B969784745ABE10C3DDBBEFE9F@UserPC>
Content-Type: text/plain; format=flowed; charset=iso-8859-1;
        reply-type=original

...I apologize for starting a new thread in this manner, but it is the only 
way that seems to work...
...can someone provide me with a reference for QuickCheck?
Thank you 




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

Message: 5
Date: Wed, 16 Mar 2011 10:27:52 -0400
From: Britt Anderson <[email protected]>
Subject: [Haskell-beginners] overload a function
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I would like to have a function that can accept more than one input
type and gives the same back as output. For the different eligible
input types there would be different tests.
An example of the idea would be something like:

test :: a -> Bool -> a

test 0 True = 0
test False True = False
.
.
.

is it obligatory that I create a typeclass for test and then instance
each type that might go in the "a" slot? Because that seems like a lot
of work.

Let me also add a general thank to those of you who support the
beginners' list. I learn something everyday.



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

Message: 6
Date: Wed, 16 Mar 2011 16:37:46 +0200
From: Alexey G <[email protected]>
Subject: [Haskell-beginners] New Thread: QuickCheck
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I think that this can help you.
http://book.realworldhaskell.org/read/testing-and-quality-assurance.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110316/17298e91/attachment-0001.htm>

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

Message: 7
Date: Wed, 16 Mar 2011 20:07:14 +0530
From: Karthick Gururaj <[email protected]>
Subject: Re: [Haskell-beginners] overload a function
To: Britt Anderson <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On Wed, Mar 16, 2011 at 7:57 PM, Britt Anderson
<[email protected]> wrote:
> I would like to have a function that can accept more than one input
> type and gives the same back as output. For the different eligible
> input types there would be different tests.
> An example of the idea would be something like:
>
> test :: a -> Bool -> a
>
> test 0 True = 0
> test False True = False
What is expected from:
test 0 False
or
test "hello" False
?

>
> is it obligatory that I create a typeclass for test and then instance
> each type that might go in the "a" slot? Because that seems like a lot
> of work.



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

Message: 8
Date: Wed, 16 Mar 2011 10:47:27 -0400
From: "Patrick Lynch" <[email protected]>
Subject: Re: [Haskell-beginners] New Thread: QuickCheck
To: "Alexey G" <[email protected]>,    <[email protected]>
Message-ID: <18B099F600404585BED9705F927A4FB5@UserPC>
Content-Type: text/plain; charset="iso-8859-1"

...it does...thank you...
  ----- Original Message ----- 
  From: Alexey G 
  To: [email protected] 
  Sent: Wednesday, March 16, 2011 10:37 AM
  Subject: [Haskell-beginners] New Thread: QuickCheck


  I think that this can help you.
  http://book.realworldhaskell.org/read/testing-and-quality-assurance.html




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


  _______________________________________________
  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/20110316/7c6c94cb/attachment-0001.htm>

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

Message: 9
Date: Wed, 16 Mar 2011 10:58:13 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Expressing the idea of a group in
        Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Wed, Mar 16, 2011 at 08:49:27AM +0000, Christian wrote:
> Hello Haskell-Experts!
> I was trying to express the notion of a (mathematical) group
> in Haskell, using type classes, as an exercise.
> If I am not mistaken, a group can be for example the Reals together with
> the multiplication operation and "1" as the neutral element.
> Or, the Reals with addition and "0".
> my first idea was to write something like
> 
>  class Group a where
>    ...
> 
> _but_, I thought, I need to parameterise, so to speak, not only using the
> type "a", but also the group operation. 
> How could I do that in Haskell? Is that even possible?

Yes, this is a problem, and it's not really possible directly.  In
this sort of situation what you often do is make two *newtypes* which
are just wrappers around the type in question, and then make a different
Group instance for each.  As an example, you can look at Data.Monoid,
which defines two newtype wrappers called Sum and Product, with
additive and multiplicative Monoid instances respectively.

(As an aside, the real numbers do *not* actually form a group under
multiplication, since 0 has no inverse.  However, the reals without 0
do.)

-Brent



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

Message: 10
Date: Wed, 16 Mar 2011 11:03:00 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] overload a function
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Wed, Mar 16, 2011 at 10:27:52AM -0400, Britt Anderson wrote:
> I would like to have a function that can accept more than one input
> type and gives the same back as output. For the different eligible
> input types there would be different tests.
> An example of the idea would be something like:
> 
> test :: a -> Bool -> a
> 
> test 0 True = 0
> test False True = False
> .
> .
> .
> 
> is it obligatory that I create a typeclass for test and then instance
> each type that might go in the "a" slot? Because that seems like a lot
> of work.

In a polymorphic function, you are not allowed to do different things
depending on the type of a polymorphic input.  Partly this is just
theoretically elegant (see "parametricity" and "free theorems"), and
practically speaking it means that types can be *erased* at compile
time.  At run time there is no way to see what type something is
because all you have is a bunch of bits, with no type information!

The only way to have a polymorphic function which does something
different for different types is to use a type class.

-Brent



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

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


End of Beginners Digest, Vol 33, Issue 19
*****************************************

Reply via email to