[clean-list] arithmetic and uniqueness

eli+@gs211.sp.cs.cmu.edu eli+@gs211.sp.cs.cmu.edu
Thu, 25 Jan 2001 17:31:17 -0500 (EST)


I've been trying to get a grasp on uniqueness typing.  It hasn't been
so easy, but I think I did figure out one piece that was confusing me.

Define a test function, and try to call it on "2+3":
foo :: !*Int -> *Int
foo x = x
Start = foo (2+3)        // fails to type

This kind of thing confused me, because I expected that 5 to be
unique.  But if you look in the standard library, the 5 is not
declared as unique -- I guess because (+) is overloaded and can't
in general guarantee any such thing.  As far as I can see, there's no
way to coerce (+) into working here, but like I said, I don't
understand uniqueness.

I don't understand the library's (+) code, but I mimicked it and gave
it a type that understands about uniqueness:

(u_plus) infixl :: !u:Int !v:Int -> w:Int,  [w<=u, w<=v]
(u_plus) a b
    = code {
    .inline u_plus;i
        addI
    .end
    }
Start = foo (2 u_plus 3)       // succeeds

This seems a little too easy.

-- 
     Eli Brandt  |  eli+@cs.cmu.edu  |  http://www.cs.cmu.edu/~eli/