Questions about sharing

Koen Claessen [email protected]
Fri, 7 Dec 2001 16:13:52 +0100 (MET)

 | Yes, GHC will common these up (with -O).  I'm not sure
 | I understand the point about the type checker not
 | letting you do this yourself, though: surely x and
 | (a:as) have the same type?

In the following definition, one is not allowed to:

  instance Functor (Either a) where
    fmap f (Left a)  = Left a
    fmap f (Right b) = Right (f b)

The first line cannot be written as:

  fmap f x@(Left a) = x

Because it does not type check!