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. FlexibleInstances (Emanuel Koczwara)
2. 'read' throws; why not maybe or either? (Patrick Redmond)
3. Re: 'read' throws; why not maybe or either? (Mateusz Kowalczyk)
4. Re: FlexibleInstances (AntC)
5. Re: FlexibleInstances (Emanuel Koczwara)
6. Re: 'read' throws; why not maybe or either? (David McBride)
7. Re: FlexibleInstances (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Sun, 24 Nov 2013 14:32:40 +0100
From: Emanuel Koczwara <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] FlexibleInstances
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"; Format="flowed"
Hi,
I have very simple code:
class XmlValue a where
toValue :: a -> String
instance XmlValue String where
toValue _ = "lorem"
It gives followingerror:
Illegal instance declaration for `XmlValue String'
(All instance types must be of the form (T t1 ... tn) where T is not
a synonym.Use -XTypeSynonymInstancesif you want to disable this.)
So, maybe I'll removethat synonym:
instance XmlValue [Char] where
toValue _ = "lorem"
This gives following error:
Illegal instance declaration for `XmlValue [Char]'
(All instance types must be of the form (T a1 ... an) where a1 ...
an are *distinct type variables*, and each type variable appears at most
once in the instance head. Use -XFlexibleInstancesif you want to disable
this.)
So, maybe I'll try to use that (T a1 ... an)form:
instance XmlValue ([] String) where
toValue _ = "lorem"
Illegal instance declaration for `XmlValue [String]'
(All instance types must be of the form (T a1 ... an) where a1 ...
an are *distinct type variables*, and each type variable appears at most
once in the instance head. Use -XFlexibleInstancesif you want to disable
this.)
Ok. Maybe I'll try to enable FlexibleInstanceswith {-# LANGUAGE
FlexibleInstances #-}
Ok, this works, but:
http://stackoverflow.com/questions/15285822/cant-make-string-an-instance-of-a-class-in-haskell(second
answer):
"
However, Haskell98 forbids this type of typeclass in order to keep
things simple and to make it harder for people to write overlapping
instances like
| instance Slang[a] where
-- Strings would also fit this definition.
slangify list= "some list"
"|
Ok, that's bad. But I want only [Char], [a] shouldn't work.
https://ghc.haskell.org/trac/haskell-prime/wiki/FlexibleInstances says,
that I'll get all or nothing.
I want to enable "instance [Char] where..." but disable "instance [a]
where...". Is it possible?
Thanks,
Emanuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131124/a6e285ae/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 25 Nov 2013 10:49:52 +1300
From: Patrick Redmond <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] 'read' throws; why not maybe or either?
Message-ID:
<CAHUea4E2j8bbELESbrjC3eEHkiGqo+bSPMPS9nd-bCMdb=i...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Is there a variation of 'read' which uses Maybe or Either to handle
failure instead of an exception?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131125/6cc9b9ab/attachment-0001.html>
------------------------------
Message: 3
Date: Sun, 24 Nov 2013 21:57:54 +0000
From: Mateusz Kowalczyk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] 'read' throws; why not maybe or
either?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 24/11/13 21:49, Patrick Redmond wrote:
> Is there a variation of 'read' which uses Maybe or Either to handle
> failure instead of an exception?
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
See
http://stackoverflow.com/questions/5121371/how-to-catch-a-no-parse-exception-from-the-read-function-in-haskell
--
Mateusz K.
------------------------------
Message: 4
Date: Sun, 24 Nov 2013 22:02:21 +0000 (UTC)
From: AntC <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] FlexibleInstances
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
> Emanuel Koczwara <poczta <at> emanuelkoczwara.pl> writes:
He Emanuel, you're doing well.
Hardly anyone these days sticks to Haskell 98;
and really there's no need to.
(What you're trying to do can be achieved with H98,
but would need some not-so-user-friendly coding.)
>
> I want to enable "instance [Char] where..." but disable "instance [a]
where...". Is it possible?
>
Yes, you're almost there.
You do need FlexibleInstances to be able to put [Char].
To ban [a], you need to ban overlapping instances.
{-# LANGUAGE NoOverlappingInstances #-}
(Usually overlapping instances is on by default.)
You're next error meesage is probably going to be,
Illegal overlapping instance declaration for ...
Avoiding them is subtle, but a valuable discipline ;-)
HTH
------------------------------
Message: 5
Date: Sun, 24 Nov 2013 23:24:11 +0100
From: Emanuel Koczwara <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] FlexibleInstances
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
W dniu 24.11.2013 23:02, AntC pisze:
> Yes, you're almost there.
> You do need FlexibleInstances to be able to put [Char].
>
> To ban [a], you need to ban overlapping instances.
> {-# LANGUAGE NoOverlappingInstances #-}
>
> (Usually overlapping instances is on by default.)
>
> You're next error meesage is probably going to be,
> Illegal overlapping instance declaration for ...
>
> Avoiding them is subtle, but a valuable discipline ;-)
>
> HTH
Thanks, exactly what I wanted :)
Regards,
Emanuel
------------------------------
Message: 6
Date: Sun, 24 Nov 2013 17:43:50 -0500
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] 'read' throws; why not maybe or
either?
Message-ID:
<CAN+Tr43wWcGxQ3YQY_UHhhzSFwvg3wysCKTrfJf-k1whJwg=e...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
You might be interested in the 'safe' package. It has a function in it
called readMay, along with a lot of other useful minor omissions from
prelude. http://hackage.haskell.org/package/Safe-0.1/docs/Safe.html
On Sun, Nov 24, 2013 at 4:49 PM, Patrick Redmond <[email protected]>wrote:
> Is there a variation of 'read' which uses Maybe or Either to handle
> failure instead of an exception?
> _______________________________________________
> 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/20131124/f08fc863/attachment-0001.html>
------------------------------
Message: 7
Date: Mon, 25 Nov 2013 05:43:20 -0500
From: Brent Yorgey <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] FlexibleInstances
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sun, Nov 24, 2013 at 10:02:21PM +0000, AntC wrote:
> > Emanuel Koczwara <poczta <at> emanuelkoczwara.pl> writes:
>
> He Emanuel, you're doing well.
> Hardly anyone these days sticks to Haskell 98;
> and really there's no need to.
> (What you're trying to do can be achieved with H98,
> but would need some not-so-user-friendly coding.)
>
> >
> > I want to enable "instance [Char] where..." but disable "instance [a]
> where...". Is it possible?
> >
>
> Yes, you're almost there.
> You do need FlexibleInstances to be able to put [Char].
>
> To ban [a], you need to ban overlapping instances.
> {-# LANGUAGE NoOverlappingInstances #-}
>
> (Usually overlapping instances is on by default.)
No, it's not.
-Brent
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 65, Issue 9
****************************************