Changes between Version 4 and Version 5 of NumericClasses


Ignore:
Timestamp:
Jun 21, 2007 4:41:53 PM (8 years ago)
Author:
ross@…
Comment:

tweak normalization

Legend:

Unmodified
Added
Removed
Modified
  • NumericClasses

    v4 v5  
    134134   For integral types (but not others), this is similar to `signum` and
    135135   `abs`, but the general idea makes sense for any integral domain.
    136  * These could be combined in a class of Euclidean domains, or there could be
    137    an intermediate class of integral domains.  In the latter case division
    138    would not be available for defining defaults.
    139136 * In algebra, each field is trivially a Euclidean domain, with the remainder
    140137   always zero.  However this would break backwards compatibility, as well as
    141138   the programming languages convention of distinguishing integer division.
    142139
     140Proposal:
     141 * Add a Euclidean domain class, with canonical factorization satisfying
     142   {{{
     143stdAssociate x * stdUnit x = x
     144stdUnit (x*y) = stdUnit x * stdUnit y
     145stdUnit x * (one `div` stdUnit x) = x
     146x*y = one  =>  stdUnit x = x
     147}}}
     148   and either `divMod` or `quotRem`.
     149 * (Could be further split by placing canonical factorization in an integral
     150   domain class, but division would not be available for default definitions,
     151   and would also need to supply the reciprocal of `stdUnit x`.)
     152
    143153Proposed new class:
    144154{{{
    145155class Ring a => EuclideanDomain a where
     156    stdAssociate    :: a -> a
     157    stdUnit         :: a -> a
     158    normalize       :: a -> (a, a)
     159
    146160    div, mod        :: a -> a -> a
    147161    divMod          :: a -> a -> (a,a)
    148162
    149     stdAssociate    :: a -> a
    150     stdUnit         :: a -> a
     163    -- Minimal complete definition:
     164    --      (stdUnit or normalize) and (divMod or (div and mod))
     165    stdAssociate x  =  x `div` stdUnit x
     166    stdUnit x       =  snd (normalize x)
     167    normalize x     =  (stdAssociate x, stdUnit x)
    151168
    152     -- Minimal complete definition:
    153     --      (divMod or (div and mod)) and stdUnit
    154169    n `divMod` d    =  (n `div` d, n `mod` d)
    155170    n `div` d       =  q  where (q,r) = divMod n d
    156171    n `mod` d       =  r  where (q,r) = divMod n d
    157 
    158     stdAssociate x  =  x `div` stdUnit x
    159172}}}
    160173Haskell 98 compatibility class: