The void package claims to provide an uninhabitable type called Void
, which is defined as follows -
newtype Void = Void Void
How is this definition any better than using something simpler? Say -
data Void
If my understanding is correct, both the data types contain only bottom values. However the latter is much easier to understand.
EDIT: Okay so I understand Daniel's answer below. However I thought of another possibly simpler way to do this while remaining Haskell98 compatible. We can use an Abstract data type and expose no constructors to the user.
module Data.Void (Void) where
data Void = Void
Now only code in Data.Void module can construct a Void, however since we know it doesn't, the Void datatype is effectively uninhabited.
Would that work or am I missing something here?
From description for the void package on Hackage: "A Haskell 98 logically uninhabited data type" (my emphasis). Declaring Void
as simply data Void
would require either Haskell 2010 or the "EmptyDataDecls" language extension and thus would not be "Haskell 98".
EDIT
Here is a page on the Haskell Wiki that describes exactly this situation.
Your implementation is still incomplete because you do not have the absurd function:
absurd :: Void -> a
Void is supposed to be an initial object in Haskell, which is why you need the absurd function. I find the implementation of absurd in the void package to be very elegant and appropriate:
absurd (Void a) = absurd a
This definition is reminiscent of the logical analogy of Void to the False premise from which any conclusion can be derived. It even uses the logical fallacy of referencing itself to prove itself, which is logically ... absurd.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With