[Haskell-beginners] Empty type
Ben Gamari
bgamari.foss at gmail.com
Fri Oct 25 05:06:22 UTC 2013
KwangYul Seo <skyul at company100.com> writes:
> Hello,
>
> It seems there are three different ways to declare an empty type in Haskell.
>
> http://www.haskell.org/haskellwiki/Empty_type
>
> 1) data E0 = E0
>
Perhaps this is a bit nit-picky, but is this truly empty? I would
actually argue that the type is inhabited by precisely one element,
`E0` (note that we aren't counting _|_).
> 2) newtype Void = Void Void
>
> 3) data Void
>
> I'd like to know how the second trick works. Is it possible to create a new
> type from itself? How should I interpret this?
>
I'll try to answer as far as I understand it but someone please correct
any mistruths below.
Consider your type,
newtype Void = Void Void
There are only two ways we could construct a value of type `Void`,
a = Void _|_
and,
b = Void b
However, `b` is a non-terminating recursion, making it equivalent to
`a`. By this reasoning, since both of these constructions evaluate to
_|_, `Void` must be empty.
Cheers,
- Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131025/97e3c220/attachment.sig>
More information about the Beginners
mailing list