[Haskell-cafe] Void vs ()
cdsmith at gmail.com
Sat Mar 25 23:51:48 UTC 2017
I'm afraid the answers so far haven't been as clear as they should. You
want (), and no one at all will be surprised by this use of ().
() is the type that says the value should contain no information. There is
one possible value; and since all values of () are the same, there's no
information contained in the choice of value. It is completely standard to
use () for situations exactly like this, where a type was designed with the
possibility of some information being communicated, but in this case
there's really nothing to say. Your situation is exactly analogous to
common uses, like IO () as the type for IO actions with no result.
So where does Void fit in? Void is a type that cannot occur at all! There
are NO possible values for Void. The result is that there are no possible
values for Foo Void e. And therefore, if you define Batch i e using Void,
the only values of Batch i e are those that have an empty list, so Batch i
e is isomorphic to Int. This is NOT what you want.
(The above is ignoring bottoms. It's true that you can create other
possible values of Foo Void e by using undefined as a value for Void. This
isn't a road you want to go down.)
On Sat, Mar 25, 2017 at 2:21 AM, Bardur Arantsson <spam at scientician.net>
> On 2017-03-25 00:45, David Feuer wrote:
> > Using Void states that the list will always be empty, because the only
> > way to put elements in it would be to fill in the Void fields with
> > bottoms.
> Right, so I kind of took it to mean "don't even bother trying to look at
> this -- there's nothing here", but I guess it could get kind of awkward
> if you were to, say, try to sort the list further. You'd have to
> purposefully avoid the field explicitly...
> Haven't go to it, but I'm probably going to go with a newtype and punt
> the naming by just doing Foo' vs Foo. After all, naming is really hard. :).
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe