<div dir="ltr">(and to be even clearer, its definitely something where any help on determining impact and minimizing it would be a pure joy to have )</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 6, 2019 at 10:42 PM Carter Schonwald <<a href="mailto:carter.schonwald@gmail.com">carter.schonwald@gmail.com</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">true, i just actually WANT to fixup those corners of float, assuming impact can be managed suitably</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 6, 2019 at 10:30 PM David Feuer <<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</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="auto">We can add laws while recognizing that some existing instances are not lawful.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Feb 6, 2019, 9:43 PM Carter Schonwald <<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</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 dir="ltr">We cant add laws at the moment unless we change how the Ord instances for Float and Double are defined. (which i think SHOULd happen, but needs some care and has lots of implications)<div><br></div><div>there are several possible semantics we can choose that act as we expect on +/- infity and finite floats, but differ in the handling of nans</div><div><br></div><div>option 1) use the total order defined in floating point standard 2008, section 5.10, which defines negative nans below -infity, positive nans above +infty</div><div>(this has the nice property that you could check for not nan by -infty <= x && x <= infty)</div><div><br></div><div>option 2) shift haskell/ GHC to having signalling NAN semantics by default, so the only "fully evaluated" floating point values are in the interval from negative to positive infinity , </div><div><br></div><div>option 3) some mixture of the above</div><div><br></div><div>I am slowly doing some patches to improve floating point bits in ghc (and pave the way towards doing something like one of the above), though theres still much to do</div><div><br></div><div>also: the current definitions of min/max via compare aren't commutative if either argument is nan (they become right biased or left biased, i forget which)</div><div><br></div><div><a href="http://www.dsc.ufcg.edu.br/~cnum/modulos/Modulo2/IEEE754_2008.pdf" rel="noreferrer" target="_blank">http://www.dsc.ufcg.edu.br/~cnum/modulos/Modulo2/IEEE754_2008.pdf</a> is a copy of ieee floating point 2008 (easy to google up a copy if that link doesnt work)<br></div><div><br></div><div><br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 6, 2019 at 4:31 PM chessai . <<a href="mailto:chessai1996@gmail.com" rel="noreferrer" target="_blank">chessai1996@gmail.com</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">Sure. There are no explicit mention of the laws of Ord. I think they<br>
should be explicitly stated in the report, perhaps like so:<br>
<br>
---------- start proposed change<br>
class (Eq a) => Ord a where<br>
compare :: a -> a -> Ordering<br>
(<), (<=), (>), (>=) :: a -> a -> Bool<br>
max, min :: a -> a -> a<br>
<br>
compare x y = if x == y then EQ<br>
else if x <= y then LT<br>
else GT<br>
<br>
x < y = case compare x y of { LT -> True; _ -> False }<br>
x <= y = case compare x y of { GT -> False; _ -> True }<br>
x > y = case compare x y of { GT -> True; _ -> False }<br>
x >= y = case compare x y of { LT -> False; _ -> True }<br>
<br>
max x y = if x <= y then y else x<br>
min x y = if x <= y then x else y<br>
{-# MINIMAL compare | (<=) #-}<br>
<br>
The `Ord` class is used for totally ordered datatypes. Instances of<br>
'Ord' can be derived for any user-defined datatype whose constituent<br>
types are in 'Ord'. The declared order of the constructors in the data<br>
declaration determines the ordering in the derived 'Ord' instances.<br>
The 'Ordering' datatype allows a single comparison to determine the<br>
precise ordering of two objects.<br>
<br>
A minimal instance of 'Ord' implements either 'compare' or '<=', and<br>
is expected to adhere to the following laws:<br>
<br>
Antisymmetry (a <= b && b <= a = a == b)<br>
Transitivity (a <= b && b <= c = a <= c)<br>
Totality (a <= b || b <= a = True)<br>
<br>
An additional law, Reflexity, is implied by Totality. It states (x <= x = True).<br>
---------- end proposed change<br>
<br>
I don't particularly like the bit in the current documentation about<br>
(<=) implementing a non-strict partial ordering, because if (<=)<br>
constitutes a minimal definition of Ord and is required only to be a<br>
partial ordering on the type parameterised by Ord, then why is Ord<br>
required to be a total ordering? That seems sort of confusing. It<br>
seems to me that the current documentation leans more toward 'Ord'<br>
implementing a partial order than a total order. I can't speak for<br>
others, but when I think of 'Ord' I usually think of a total ordering.<br>
<br>
Additionally, Reflexity is strictly weaker than Totality, so<br>
specifying their relationship (Reflexivity is implied by Totality) and<br>
also writing out what Totality means in the context of Ord makes sense<br>
to me.<br>
<br>
For Eq, the report currently states:<br>
<br>
----------begin report quote<br>
class Eq a where<br>
(==), (/=) :: a -> a -> Bool<br>
<br>
x /= y = not (x == y)<br>
x == y = not (x /= y)<br>
<br>
The Eq class provides equality (==) and inequality (/=) methods. All<br>
basic datatypes except for functions and IO are instances of this<br>
class. Instances of Eq can be derived for any user-defined datatype<br>
whose constituents are also instances of Eq.<br>
<br>
This declaration gives default method declarations for both /= and ==,<br>
each being defined in terms of the other. If an instance declaration<br>
for Eq defines neither == nor /=, then both will loop. If one is<br>
defined, the default method for the other will make use of the one<br>
that is defined. If both are defined, neither default method is used.<br>
----------end report quote<br>
<br>
I think the following changes make sense:<br>
<br>
---------- begin proposed changes<br>
<br>
class Eq a where<br>
(==), (/=) :: a -> a -> Bool<br>
x /= y = not (x == y)<br>
x == y = not (x /= y)<br>
<br>
The 'Eq' class defines equality ('==') and inequality ('/=').<br>
All the basic datatypes exported by the "Prelude" are instances of 'Eq',<br>
and 'Eq' may be derived for any datatype whose constituents are also<br>
instances of 'Eq'.<br>
<br>
'==' implements an equivalence relationship where two values comparing equal<br>
are considered indistinguishable. A minimal instance of 'Eq'<br>
implements either '==' or '/=', and must adhere to the following laws:<br>
<br>
Reflexivity (x == x = True)<br>
Symmetry (x == y = y == x)<br>
Transitivity (x == y && y == z = x == z)<br>
Substitutivity (x == y = f x == f y)<br>
Negation (x /= y = not (x = y)<br>
---------- end proposed changes<br>
<br>
On Wed, Feb 6, 2019 at 3:52 PM Herbert Valerio Riedel<br>
<<a href="mailto:hvriedel@gmail.com" rel="noreferrer" target="_blank">hvriedel@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
><br>
><br>
> On Wed, Feb 6, 2019 at 9:43 PM chessai . <<a href="mailto:chessai1996@gmail.com" rel="noreferrer" target="_blank">chessai1996@gmail.com</a>> wrote:<br>
>><br>
>> Per GHC.Classes (haddock-viewable from Data.Ord)<br>
>><br>
>> "The Haskell Report defines no laws for Ord. However, <= is<br>
>> customarily expected to implement a non-strict partial order and have<br>
>> the following properties:"<br>
>><br>
>> I propose that in the next report that the expected typeclass laws for<br>
>> Ord be added. They're generally agreed upon/understood.<br>
><br>
><br>
><br>
> Can you spell out the concrete change to the report wording you're suggesting? For reference, the current wording used in the 2010 Haskell Report is quoted below. While at it, you might also want to take into account the `Eq` class definition in the report.<br>
><br>
><br>
> 6.3.2 The Ord Class<br>
><br>
> class (Eq a) => Ord a where<br>
> compare :: a -> a -> Ordering<br>
> (<), (<=), (>=), (>) :: a -> a -> Bool<br>
> max, min :: a -> a -> a<br>
><br>
> compare x y | x == y = EQ<br>
> | x <= y = LT<br>
> | otherwise = GT<br>
><br>
> x <= y = compare x y /= GT<br>
> x < y = compare x y == LT<br>
> x >= y = compare x y /= LT<br>
> x > y = compare x y == GT<br>
><br>
> -- Note that (min x y, max x y) = (x,y) or (y,x)<br>
> max x y | x <= y = y<br>
> | otherwise = x<br>
> min x y | x <= y = x<br>
> | otherwise = y<br>
><br>
> The Ord class is used for totally ordered datatypes. All basic datatypes except for functions, IO, and IOError, are instances of this class. Instances of Ord can be derived for any user-defined datatype whose constituent types are in Ord. The declared order of the constructors in the data declaration determines the ordering in derived Ord instances. The Ordering datatype allows a single comparison to determine the precise ordering of two objects.<br>
><br>
> The default declarations allow a user to create an Ord instance either with a type-specific compare function or with type-specific == and <= functions.<br>
><br>
><br>
><br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" rel="noreferrer" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" rel="noreferrer" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div>