<div dir="ltr"><div>I think the fundamental question is what is fundamental to `Bounded`/`Enum`?</div><div><br></div><div>1. Do the suggested `Bounded` laws:<br></div><div><br></div><div> minBound <= x</div><div> maxBound >= x</div><div><br></div><div> hold independently of an `Enum` instance? The docs suggests the `Ord` constraint on `Bounded` is only missing because there is no partial ordering class in base.<br></div><div><br></div><div><div>2. Are `Enum`/`Bounded` defined as a pair that is independent of `Ord` with `minBound`/`maxBound` only reasoned about in the context of a possible `Enum` instance.</div></div><div><br></div><div>With (1) we get the problematic derived `Enum a => Enum (Down a)` instance because that gives e.g. `succ (maxBound :: Down Bool) = succ (Down False) = (derived instance uses underlying Enum) = succ False = True /= error`<br></div><div><br></div><div>In this instance, would need a different `Enum a => Enum (Down a)` instance where the laws you suggest would fix the choice of `fromEnum` to one of the form `fromEnum = negate . fromEnum . getDown` rather than `fromEnum = fromEnum . getDown`.</div><div><br></div><div>With (2), everything works OK and as before for `Enum`/`Bounded` but we do get e.g. `forall (x :: Down Int). minBound @(Down Int) >= x`.</div><div><br></div><div>David.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 18, 2020 at 5:57 PM Ganesh Sittampalam <<a href="mailto:ganesh@earth.li">ganesh@earth.li</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>Is the fundamental question whether we require that types that
implement both Ord and Enum have these laws?</p>
<blockquote>
<p> <font size="+1"><tt>succ x > x</tt><tt><br>
</tt></font></p>
<p><font size="+1"><tt>x > y == fromEnum x > fromEnum y</tt></font></p>
</blockquote>
<p>If we require it then this change is mandatory, if we don't
require that then it's optional and whatever argument we have
against the laws might be an argument against this change.<br>
</p>
<p><br>
</p>
<div>On 18/09/2020 17:19, David Beacham
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>That is a good spot - I had wondered if the
minBound/maxBound changes would affect other classes but had
missed Enum.</div>
<div><br>
</div>
<div>I wouldn't be surprised that `Down a` had a reversed
enumeration despite the `Ord`/`Enum` separation.</div>
<div><br>
</div>
<div>
<div>Looking at the `Bounded` docs</div>
</div>
<div>
<div><br>
</div>
<div>> The Bounded class is used to name the upper and
lower limits of a type. Ord is not a superclass of Bounded
since types that are not totally ordered may also have upper
and lower bounds.</div>
<div><br>
</div>
<div>does suggest that flipping minBound and maxBound is
correct? That would then require `Enum a => Enum (Down
a)` should also be flipped given the way it interacts with
`Bounded`?</div>
</div>
<div><br>
</div>
<div>I think the instance is achievable by</div>
<div><br>
</div>
<div>1. flipping pred/succ</div>
<div>2. carefully using "negated Int"s when looking at
`fromEnumThenTo` etc.</div>
<div><br>
</div>
<div>I think you get the choice of keeping the same `Int`
conversions, `toEnum = Down . toEnum`, or negating it, `toEnum
= Down . toEnum . negate`, so e.g. 0 -> False, 1 -> True
becomes 0 -> Down False, -1 -> Down True.</div>
<div><br>
</div>
<div>I can add potential implementations to the MR so that there
is something concrete to look at (and check it all works) or
do it here.<br>
</div>
<div><br>
</div>
<div>But I think it all needs a bit more discussion than I'd
initially thought!</div>
<div><br>
</div>
<div>David.<br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Fri, Sep 18, 2020 at 3:41
PM Oleg Grenrus <<a href="mailto:oleg.grenrus@iki.fi" target="_blank">oleg.grenrus@iki.fi</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>Is it (a bug)?<br>
<br>
What about [minBound .. maxBound]. If you change
`Bounded`, you need to change `Enum` too.<br>
<br>
From
<a href="https://hackage.haskell.org/package/base-4.14.0.0/docs/GHC-Enum.html#t:Enum" target="_blank">https://hackage.haskell.org/package/base-4.14.0.0/docs/GHC-Enum.html#t:Enum</a><br>
<br>
- The calls succ maxBound and pred minBound should result
in a runtime error.<br>
- enumFrom and enumFromThen should be defined with an
implicit bound</p>
<p>The `min` and `max` in `minBound/maxBound` are related to
`succ`, `pred`, not to `compare`. If you argue against,
then we should add `Ord` super-class to `Enum` (and
`Bounded`).<br>
</p>
<p>- Oleg<br>
</p>
<div>On 18.9.2020 16.54, Carter Schonwald wrote:<br>
</div>
<blockquote type="cite">
<div dir="auto">Def a bug! Plz at myself and the core
libraries handle for code review plz. </div>
<div dir="auto"><br>
</div>
<div dir="auto">This sounds kinda related to an MR that
has languished too long regarding the behavior of Down
on Ord1, which I think is related??? (I tried to
arbitrate / layout possible answers for the related
issue in the associated mr, but none of the clc members
have engaged in the design space challenge)</div>
<div><br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Fri, Sep 18, 2020
at 7:44 AM David Beacham <<a href="mailto:mail@dbeacham.co.uk" target="_blank">mail@dbeacham.co.uk</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div>Hi all,</div>
<div><br>
</div>
<div>The current instance for `Bounded a =>
Bounded (Down a)` derives the `minBound` and
`maxBound` exactly as they are for the
underlying type `a` where I think they should be
flipped to respect the flipped ordering of `Down
a`?</div>
<div><br>
</div>
<div>I have a feeling this has been come up in
some other context/list before but I couldn't
find a reference to it when searching - so sorry
if this is a duplicate.</div>
<div><br>
</div>
<div>I've got a corresponding MR here: <a href="https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4081" target="_blank">https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4081</a></div>
<div><br>
</div>
<div>Thanks, David.<br>
</div>
</div>
<br>
<br>
_______________________________________________<br>
<br>
Libraries mailing list<br>
<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
<br>
</blockquote>
</div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
Libraries mailing list
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a>
</pre>
</blockquote>
</div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
Libraries mailing list
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a>
</pre>
</blockquote>
</div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>