Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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: How to manage typeclass hierarchies and instances?
(Stuart Hungerford)
2. Re: How to manage typeclass hierarchies and instances?
(Michael Orlitzky)
3. Re: How to manage typeclass hierarchies and instances?
(Brandon Allbery)
4. Re: How to manage typeclass hierarchies and instances?
(PATRICK BROWNE)
5. Re: How to manage typeclass hierarchies and instances?
(PATRICK BROWNE)
----------------------------------------------------------------------
Message: 1
Date: Sun, 22 Feb 2015 08:15:53 +1100
From: Stuart Hungerford <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How to manage typeclass hierarchies
and instances?
Message-ID:
<CAG+kMrF3PEp0xbYs7pCNDTfaAi-y=hbr6teuhec+-qpdgk4...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
>> -- in Semigroup.hs
>>
>> class Semigroup a where
>> (|.|) :: a -> a -> a
>>
>> instance Semigroup Integer where
>> (|.|) = (+)
>>
>>
>> -- In Monoid.hs
>>
>> class (Semigroup a) => Monoid a where
>> identity :: a
>>
>> instance Monoid Integer where
>> identity = 0
>>
>>
>> -- In Group.hs
>>
>> class (Monoid a) => Group a where
>> inverse :: a -> a
>>
>> instance Group Integer where
>> (|.|) = (+)
>> identity = 0
>> inverse = (-)
>>
>>
>> In Group.hs I'm trying to create an (additive) group instance for
>> Integer values but GHC complains that (|.|) and identity are not
>> "visible" typeclass methods.
>
> You only get one instance per type, so the Semigroup/Monoid instances
> for Integer are "set in stone." When you "import Semigroup" and "import
> Monoid", those instances come into scope. So in Group.hs, '|.|' and
> 'identity' are already defined for Integer. All you need is,
>
> instance Group Integer where
> inverse = negate
Thanks for that insight. Ignoring the instance issue for a minute,
suppose I wanted to define a typeclass Additive where I'd like to set
default implementations for the methods:
class (Num a, Group a) => Additive a where
(|.|) = (+)
-- etc...
In this situation GHC says (|.|) is not a visible method. If I add a
type declaration for (|.|) am I effectively "shadowing" the method
from Semigroup with a new method rather than supplying a default
implementation?
Thanks,
Stu
------------------------------
Message: 2
Date: Sat, 21 Feb 2015 18:44:21 -0500
From: Michael Orlitzky <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How to manage typeclass hierarchies
and instances?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
On 02/21/2015 04:15 PM, Stuart Hungerford wrote:
>
> Thanks for that insight. Ignoring the instance issue for a minute,
> suppose I wanted to define a typeclass Additive where I'd like to set
> default implementations for the methods:
>
> class (Num a, Group a) => Additive a where
> (|.|) = (+)
>
> -- etc...
>
> In this situation GHC says (|.|) is not a visible method. If I add a
> type declaration for (|.|) am I effectively "shadowing" the method
> from Semigroup with a new method rather than supplying a default
> implementation?
>
I don't think you can do that, but I wouldn't swear to it. One problem
would be that you could declare a Semigroup instance of Integer
independently of the Additive instance, and GHC would have to choose
which operation to use. In this case Additive is more specific than
Semigroup, but my instinct would be to prefer the Semigroup "override."
I think some of these things are addresses in,
https://ghc.haskell.org/trac/ghc/wiki/IntrinsicSuperclasses
but I've never made it through the whole document =)
------------------------------
Message: 3
Date: Sat, 21 Feb 2015 19:04:02 -0500
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to manage typeclass hierarchies
and instances?
Message-ID:
<CAKFCL4XaAmSXMqHWbh5U2dqPUNmLOdGRr8tK9k=wia5W=-_...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Sat, Feb 21, 2015 at 6:44 PM, Michael Orlitzky <[email protected]>
wrote:
> I don't think you can do that
You can't, at present. (Note: Typeclasses are not OOP classes; `class (Num
a, Group a) => Additive a` does not declare superclasses, but
prerequisites.)
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150221/71308dc8/attachment-0001.html>
------------------------------
Message: 4
Date: Sun, 22 Feb 2015 07:53:12 +0000
From: PATRICK BROWNE <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to manage typeclass hierarchies
and instances?
Message-ID:
<cagflrkemvr85bjjquvdsdbfwnshsoa64hnetwypgm0ikghz...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On 22 February 2015 at 00:04, Brandon Allbery <[email protected]> wrote:
> You can't, at present. (Note: Typeclasses are not OOP classes; `class (Num
> a, Group a) => Additive a` does not declare superclasses, but
> prerequisites.)
>
In logic we would say (Num a AND Group a) is a necessary condition for (
Additive a) => (Num a AND Group a) to hold.
--
This email originated from DIT. If you received this email in error, please
delete it from your system. Please note that if you are not the named
addressee, disclosing, copying, distributing or taking any action based on
the contents of this email or attachments is prohibited. www.dit.ie
Is ? ITB?C a th?inig an r?omhphost seo. M? fuair t? an r?omhphost seo tr?
earr?id, scrios de do ch?ras ? le do thoil. Tabhair ar aird, mura t? an
seola? ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon ch?ipe?il, aon
d?ileadh n? ar aon ghn?omh a dh?anfar bunaithe ar an ?bhar at? sa
r?omhphost n? sna hiat?in seo. www.dit.ie
T? ITB?C ag aistri? go Gr?inseach Ghorm?in ? DIT is on the move to
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150222/f68d25fb/attachment-0001.html>
------------------------------
Message: 5
Date: Sun, 22 Feb 2015 08:07:44 +0000
From: PATRICK BROWNE <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to manage typeclass hierarchies
and instances?
Message-ID:
<CAGFLrKfjCn5f+h3TTnSrrTa3WJ_A_nL2Tb=3wwv_o8p55g4...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
OPPS! My previous email should have be stated as a question rather than a
statement!
class (Num a, Group a) => Additive a
Or maybe given ( Additive a) => (Num a AND Group a).
Then (Num a AND Group a) is a necessary condition for (Additive a) to
hold.
On 22 February 2015 at 07:53, PATRICK BROWNE <[email protected]> wrote:
>
> On 22 February 2015 at 00:04, Brandon Allbery <[email protected]> wrote:
>
>> You can't, at present. (Note: Typeclasses are not OOP classes; `class
>> (Num a, Group a) => Additive a` does not declare superclasses, but
>> prerequisites.)
>>
>
> In logic we would say (Num a AND Group a) is a necessary condition for (
> Additive a) => (Num a AND Group a) to hold.
>
>
--
This email originated from DIT. If you received this email in error, please
delete it from your system. Please note that if you are not the named
addressee, disclosing, copying, distributing or taking any action based on
the contents of this email or attachments is prohibited. www.dit.ie
Is ? ITB?C a th?inig an r?omhphost seo. M? fuair t? an r?omhphost seo tr?
earr?id, scrios de do ch?ras ? le do thoil. Tabhair ar aird, mura t? an
seola? ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon ch?ipe?il, aon
d?ileadh n? ar aon ghn?omh a dh?anfar bunaithe ar an ?bhar at? sa
r?omhphost n? sna hiat?in seo. www.dit.ie
T? ITB?C ag aistri? go Gr?inseach Ghorm?in ? DIT is on the move to
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150222/dbf342df/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 80, Issue 61
*****************************************