() Enum Intstance Intentionally Throws Runtime Error

WHY!?

instance Enum () where
    succ _      = errorWithoutStackTrace "Prelude.Enum.().succ: bad argument"
    pred _      = errorWithoutStackTrace "Prelude.Enum.().pred: bad argument"

This seems so stupid! Maybe Iā€™m missing something.

From the Enum docs:

2 Likes

Unit seems like it could be an exception since it is often used as a place holder, but I guess lazyness allows for this to still work as long as it is never resolved.

I think Enum was/is primarily intended to be used through list comprehension notation. Even with that strange instance it does not go wrong, e.g. [() .. ()] and [() ..] both work fine.

1 Like

Might you be interested in todo?

1 Like

question is, why does () have Enum and Bounded instances

instance Bounded () instance does not seem controversial to me. And Enum instances are almost guaranteed to be partial, so one more error does not make a difference.

7 Likes