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: pattern matching on strings ? (Chadda? Fouch?)
2. Re: pattern matching on strings ? (Roelof Wobben)
3. How to manage typeclass hierarchies and instances?
(Stuart Hungerford)
4. Re: How to manage typeclass hierarchies and instances?
(Michael Orlitzky)
----------------------------------------------------------------------
Message: 1
Date: Fri, 20 Feb 2015 13:40:57 +0100
From: Chadda? Fouch? <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] pattern matching on strings ?
Message-ID:
<CANfjZRYmRCiahfD4NCuE+wY=skmqh6zftinsyjzhywj9ccd...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
>
> On Fri, 20 Feb 2015 08:32:17 +0100, Roelof Wobben <[email protected]>
> wrote:
>
> First I thought to split the string on the " " but according to google
>> Haskell do not have a split function.
>
>
As others have already said, Haskell does in fact have a "split on spaces"
function (words), and several others flavors of splitting that makes it
possible to dissect your list as you wish. If you still want a split
function ala Perl, there is a solid "split
<https://hackage.haskell.org/package/split>" package on hackage which
propose several standard function and a very configurable generic version
of the split concept for all lists. Also, Data.Text comes with several
splitting functions for use with the Text datatype.
--
Jeda?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150220/e6f94f77/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 20 Feb 2015 15:30:44 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] pattern matching on strings ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150220/c2bfb9c1/attachment-0001.html>
------------------------------
Message: 3
Date: Sat, 21 Feb 2015 10:58:36 +1100
From: Stuart Hungerford <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] How to manage typeclass hierarchies and
instances?
Message-ID:
<cag+kmrhvucyddks4ga7sepv+qdy-autkvecz8t_fa5u8qyp...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Hi,
I'm experimenting with Haskell typeclasses and could do with some
advice on managing superclasses and instance declarations. Suppose I
have these modules (please ignore any misunderstandings of abstract
algebra concepts):
-- 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.
I understand that if I explicitly recreate Semigroup and Monoid
instances for Integer in Group.hs it will fix the visibility issue--at
the cost of duplicating the instances already defined in Semigroup.hs
and Monoid.hs.
I'm starting to wonder whether it's a good idea to create typeclass
instances in the same modules as the typeclass definitions? In my case
I could create a separate Instances.hs with the instance declarations
but how do Haskellers generally handle this situation?
Thanks,
Stu
------------------------------
Message: 4
Date: Fri, 20 Feb 2015 22:09:45 -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/20/2015 06:58 PM, Stuart Hungerford wrote:
> Hi,
>
> I'm experimenting with Haskell typeclasses and could do with some
> advice on managing superclasses and instance declarations. Suppose I
> have these modules (please ignore any misunderstandings of abstract
> algebra concepts):
>
> -- 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
To add different instances, you'll need a newtype wrapper around Integer.
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 80, Issue 58
*****************************************