[Haskell-cafe] No Enum for (,), no Enum or Bounded for Either

MarLinn monkleyon at gmail.com
Fri Jun 1 19:28:07 UTC 2018


Counterargument: overlapping instances

     instance (Bounded b, Enum b) => Enum (Either a b)
     instance (Bounded b) => Bounded (Either a b)
     instance (Applicative f, Bounded a) => Bounded (f a)
     instance (Bounded a, Enum a) => Enum (Either a b)
     instance (Bounded a) => Bounded (Either a b)
     instance (Bounded a, Enum a, Monoid b) => Enum (a, b)
     instance (Bounded b, Enum b, Monoid a) => Enum (a, b)

Also note that what you're talking about is a special type of objects, 
namely

     type BoundedEnum a = (Bounded a, Enum a) -- using ConstraintKinds

(I'm sure the mathematicians have a better name for this)

So IF someone where to add these somewhere, might I suggest also adding 
essentials like

     enumAll :: (Bounded a, Enum a) => [a]
     -- i.e. enumAll :: (BoundedEnum a) => [a]

Lastly, because it's its own type of objects, I'm sure there's a library 
out there doing just that. (Plus maybe other stuff like EnumMap's).

On 2018-06-01 20:32, Tom Ellis wrote:
> True.  I think I would propose
>
>      instance (Bounded a, Bounded b, Enum a, Enum b) => Enum (Either a b)
>      instance (Bounded a, Bounded b) => Enum (Bounded a b)
>      instance (Bounded a, Bounded b, Enum a, Enum b) => Enum (a, b)
>
> On Fri, Jun 01, 2018 at 02:23:58PM -0400, Li-yao Xia wrote:
>> One issue is that (Int, Int) is too big to define toEnum/fromEnum.
>>
>> On 06/01/2018 02:10 PM, Tom Ellis wrote:
>>> I'm a bit surprised that whilst `Either` and `(,)` have instances for `Ord`
>>>
>>> * `(,)` has no instance for `Enum`
>>> * `Either` has no instance for `Enum` or `Bounded`
>>>
>>> Is there a particular reason for that?  It might be tricky to implement
>>>
>>>       toEnum :: Int -> a
>>>       fromEnum :: a -> Int
>>>
>>> but in the presence of `Bounded` that should be possible.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180601/756c746c/attachment.html>


More information about the Haskell-Cafe mailing list