Void type in base

Shachaf Ben-Kiki shachaf at gmail.com
Wed Jul 17 07:14:18 CEST 2013


It seems strange that there's a canonical unit type -- () -- which is
used extensively, but no canonical type for its dual, the uninhabited
type. The closest we have is in Edward Kmett's void package, but
several people seem to prefer to write it themselves rather than incur
an extra dependency, which is a shame.

The proposal is just to copy the Data.Void API into base:

    data Void -- EmptyDataDecls is in Haskell 2010
    absurd :: Void -> a
    vacuous :: Functor f => f Void -> f a
    -- instances for Typeable, Data, Generic, Eq, Ord, Show, Read, Ix, Exception

(void also has a vacuousM for Monad, but since Functor will probably
become a superclass, it might not be necessary to export it... By
default it probably makes sense to include it, though.)

void could then re-export Data.Void so packages that depend on it will
keep working.

("void" also has unsafe functions -- namely unsafeVacuous, which isn't
safe with an invalid Functor instance -- but those probably don't
belong in base.)

hashable and semigroups would also need to be updated to add their
respective instances as non-orphans.

The instances should probably be made compatible with void's. In
particular note that void's Eq instance has `_ == _ = True`.

Discussion period: 2 weeks.

    Shachaf




More information about the Libraries mailing list