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

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Fri Jun 1 19:33:18 UTC 2018


Sorry, could you explain further?  I don't understand what the
implementation of any of those proposed instances is supposed to be.

On Fri, Jun 01, 2018 at 09:28:07PM +0200, MarLinn wrote:
> 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.
> 

> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.



More information about the Haskell-Cafe mailing list