> > > class Aggregate a where
> > >  toList::(Num b)=>a->[b]
> > >  fromList::(Num b)=>[b]->a
> > 
> > > data MyAgg =Agg Int Int
> > > instance Aggregate MyAgg where
> > >  toList (Agg x y) = [x,y]
> > >  fromList [x,y] = (Agg x y)

> I understand what it is saying.  I don't understand why it is a problem. 
> MyAgg abides by the rules of Aggregate and will never cause a type error
> when passed to a function that requires an Aggregate.  Why should MyAgg be
> illegal?
OK, I'll say it again:  toList has the typing
  toList :: (Aggregate a, Num b) => a -> [b]
i.e., when passed an Aggregate it must be able to to turn it into
a list of ANY Num type.  Just picking one (in your case Int)
isn't good enough, it must deliver whatever the context requires
in Num, e.g. 
        1.3 : toList (Agg 1 2)
should work.  But your instance toList does not deliver ANY Num
instance, it always delivers Int, so it does not have the type that
toList must have.  You seem to be confusing existential with
universal quantification.
You can make toList work by
  toList (Agg x y) = [fromInt x, fromInt y]
To make fromList work you need to decide how to convert an
arbitrary Num to an Int.  Haskell provides no answer to this
since it's not obvious what you'd do.

        -- Lennart


Reply via email to