redefining a type class for one instance?

I am trying as an experiment to write something as follows: data Wrapper a b where Pure :: (a -> b) -> Wrapper a b Nullable :: (Maybe a -> b) -> Wrapper a b class Liftable a b where liftTo :: (b -> c) -> a b c instance Liftable Wrapper a where liftTo = Pure instance Liftable Wrapper (Maybe a) where liftTo = Nullable Obviously this code (with suitable extensions enabled) complains of overlapping type instances, but is there a way to accomplish redefining a class instance for one particular group of types while having it defined for all others? (Maybe a vs. a in this instance) -- Edward Amsden Student Computer Science Rochester Institute of Technology www.edwardamsden.com

On Tue, 12 Apr 2011, Edward Amsden wrote:
I am trying as an experiment to write something as follows:
data Wrapper a b where Pure :: (a -> b) -> Wrapper a b Nullable :: (Maybe a -> b) -> Wrapper a b
class Liftable a b where liftTo :: (b -> c) -> a b c
instance Liftable Wrapper a where liftTo = Pure
Would it be ok, to erm wrap 'a', say newtype Generic a = Generic a instance Liftable Wrapper (Generic a) where liftTo = ...
instance Liftable Wrapper (Maybe a) where liftTo = Nullable

On Tue, Apr 12, 2011 at 3:13 PM, Henning Thielemann
On Tue, 12 Apr 2011, Edward Amsden wrote:
I am trying as an experiment to write something as follows:
data Wrapper a b where Pure :: (a -> b) -> Wrapper a b Nullable :: (Maybe a -> b) -> Wrapper a b
class Liftable a b where liftTo :: (b -> c) -> a b c
instance Liftable Wrapper a where liftTo = Pure
Would it be ok, to erm wrap 'a', say
newtype Generic a = Generic a
instance Liftable Wrapper (Generic a) where liftTo = ...
That rather defeats the purpose, as the point is to have a type level dispatch on whether or not we can use a certain constructor or just a general "all-purpose" constructor. This requires the user to decide to wrap 'a' in Generic and not do the same for Maybe a.
instance Liftable Wrapper (Maybe a) where liftTo = Nullable
-- Edward Amsden Student Computer Science Rochester Institute of Technology www.edwardamsden.com
participants (2)
-
Edward Amsden
-
Henning Thielemann