Changes between Version 4 and Version 5 of NumericClasses
 Timestamp:
 Jun 21, 2007 4:41:53 PM (9 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

NumericClasses
v4 v5 134 134 For integral types (but not others), this is similar to `signum` and 135 135 `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 be137 an intermediate class of integral domains. In the latter case division138 would not be available for defining defaults.139 136 * In algebra, each field is trivially a Euclidean domain, with the remainder 140 137 always zero. However this would break backwards compatibility, as well as 141 138 the programming languages convention of distinguishing integer division. 142 139 140 Proposal: 141 * Add a Euclidean domain class, with canonical factorization satisfying 142 {{{ 143 stdAssociate x * stdUnit x = x 144 stdUnit (x*y) = stdUnit x * stdUnit y 145 stdUnit x * (one `div` stdUnit x) = x 146 x*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 143 153 Proposed new class: 144 154 {{{ 145 155 class Ring a => EuclideanDomain a where 156 stdAssociate :: a > a 157 stdUnit :: a > a 158 normalize :: a > (a, a) 159 146 160 div, mod :: a > a > a 147 161 divMod :: a > a > (a,a) 148 162 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) 151 168 152  Minimal complete definition:153  (divMod or (div and mod)) and stdUnit154 169 n `divMod` d = (n `div` d, n `mod` d) 155 170 n `div` d = q where (q,r) = divMod n d 156 171 n `mod` d = r where (q,r) = divMod n d 157 158 stdAssociate x = x `div` stdUnit x159 172 }}} 160 173 Haskell 98 compatibility class: