DDC/ClosureTyping
From HaskellWiki
< DDC
1 Region sharing
Consider the following function:
f () = do x = 5 g () = x g
Without closure information this function would have the following type:
f :: forall %r. () -> () -> Int %r
forall %r
twoSeparateInts :: Tuple2 %r1 (Int %r2, Int %r3) twoSeparateInts = (f () (), f () ())
twoSeparateInts
Int
Const
Mutable
f
f_unit :: forall %r1. () -> Int %r1 f_unit = f ()
Int
x
g
2 Closure typing for region sharing
Closure typing is used to track the sharing of regions between function calls like this one.
The type inferred forf
f :: forall %r0 . () -> () -($c0)> Int %r0 :- $c0 = x : %r0
$c0
%r0
x : %r0
Similarly to variables in the expression language, the exact names given to closure terms is not significant to the type system. However, to make inferred types easier to read, DDC names the closure terms in a function's type after the free variables that gave rise to those terms. The user is free to use whatever names they wish in type signatures. Two closure terms with different names but identical right hand sides are taken as being equivalent.
If we use this new type and apply the first argument we have:
f_unit :: () -($c0)> Int %r0 :- $c0 = x : %r0
f_unit
Int
Int
