[clean-list] Typing polymorphic CAFs

Vag vag.vagoff at gmail.com
Wed Sep 2 15:08:23 MEST 2009


module c
import StdEnv ; Start = testcafI ; testcafI :: Int ; testcafI = testcaf1
class minValue a :: a
instance minValue Int where minValue = 0x80000000 /* we are using
INT32 machines for now */
minValueOf :: a -> a | minValue a
minValueOf _ = minValue
minValueOf2 = minValueOf testcaf2
minValueOf1 = minValueOf testcaf1
// ------------------------------

testcaf1 = if (minValueOf testcaf1 == zero) one (one + one)

testcaf2 = if (minValueOf2 == zero) one (one + one)

//testcaf3 = if (minValueOf2 == zero) one (one + one)

1. testcaf1 is ok, but testcaf2 and testcaf3 contain overloading
ambiguities. Compiler complains only about testcaf3 (testcaf2 compiled
ok). Why?

2. If inferred type for testcaf1 (testcaf1 :: a | + a & one a & == a &
zero a & minValue a) or for testcaf2 (testcaf2 :: a | + a & one a & ==
a & zero a & minValue a) is inserted, compiler gives "internal
overloading could not be solved" for both. Why compiler does not eat
types inferred by itself?


More information about the clean-list mailing list