Why not allow empty record updates?

Evan Laforge qdunkan at gmail.com
Wed Nov 23 20:59:52 CET 2011


> Another place this problem has come up for me is in wanting to ensure
> representation sharing for values constructed by data constructors which
> don't make use of their type parameters. A trivial example would be sharing
> the representation of Nothing between all the Maybe types, or sharing the
> empty list among all the list types. That example isn't especially
> motivating, but there are other cases where we can end up with a large
> structure for which the type parameters are 'phantom' even though they may
> not be phantom in general (because other data constructors make use of
> them). That we want type updates for records with phantom types is just a
> symptom of the larger issue of wanting type updates for all
> quasiphantom/pseudophantom types.

I feel like this is similar (or the same) as an issue I've had like:

data X a = A a | B Z Z | C Z | D Z Z Z

-- | Cast the type by stripping out an A.
cast :: X a -> Maybe (X b)
cast x = case x of
  A _ -> Nothing
  no_a -> Just no_a

Except of course that no_a isn't going to work, I have to write case
branches for B, C, and D and reconstruct them exactly the same way
only with a different type, even though it's a type they don't depend
on.  I assume sharing is destroyed, but it seems like it should be
possible to keep it, just like the various types of Nothing and [].



More information about the Glasgow-haskell-users mailing list