
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-... 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

Emanuel Koczwara
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

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

On Sun, Nov 24, 2013 at 10:02:21PM +0000, AntC wrote:
Emanuel Koczwara
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
participants (3)
-
AntC
-
Brent Yorgey
-
Emanuel Koczwara