[Haskell-cafe] No Enum for (,), no Enum or Bounded for Either
Brandon Allbery
allbery.b at gmail.com
Fri Jun 1 19:33:30 UTC 2018
The BoundedEnum thing is already something of a sunk cost, since there's
already magic behavior of Enum when a type is also Bounded. (Go look at how
Enum deriving is specified.)
On Fri, Jun 1, 2018 at 3:28 PM MarLinn <monkleyon at gmail.com> 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.
--
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180601/c12d9167/attachment.html>
More information about the Haskell-Cafe
mailing list