Changes between Version 7 and Version 8 of TypeNats/Operations
 Timestamp:
 Jan 27, 2011 5:53:01 AM (5 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

TypeNats/Operations
v7 v8 27 27 == Solving Constraints == 28 28 29 Comparison rules: 29 There is a set of builtin instances, defining the behavior of each the typelevel operations. These instances are consistent with the theory of arithmetic on natural numbers but they are not complete (i.e., GHC is not perfect at math). This means that GHC might reject some programs 30 because it cannot solve all the necessary constraints, even though the constraint can be solved in the general theory of natural numbers. The most common cause of this is when a programmer writes down a type signature, but GHC infers a slightly different type for the implementation. Now, GHC needs to check that the specified type is compatible with the implementation. If it fails do this, then the program will be rejected. The usual workaround in such situations is to modify the type signature so that it lists explicitly the constraints that GHC could not solve. If you encounter the same problem often, please consider sending an email to the GHC mailing list to let us know. We might be able to teach GHC some more math! 31 32 33 Basic rules: 30 34 {{{ 31 35 instance m <= n  for concrete numbers m, n with m <= n … … 34 38 instance (a <= b, b <= c) => (a <= c)  (under construction) 35 39 40 type instance m + n = mn  for concrete numbers m, n, mn, with m + n = mn 41 type instance 0 + a = a 42 type instance a + a = 2 * a 43 type instance a + m = m + a  for a concrete number m 36 44 45 type instance m + n = mn  for concrete numbers m, n, mn, with m * n = mn 46 type instance 0 * a = a 47 type instance 1 * a = a 48 type instance a * a = a ^ 2 49 type instance m * a = a * m  for concrete numbers m 50 51 type instance m + n = mn  for conrete numbers m, n, mn, with m ^ n = mn 52 type instance 1 ^ a = 1 53 type instance a ^ 0 = 1 54 type instance a ^ 1 = a 55  type instance a ^ m = a simplified to a <= 1 37 56 }}} 57 58 59