Type variables introduced by a type signature for a term remain in scope throughout the definition of that term.
For example in the following snippet, the type annotation
temp:xis telling Unison that
temphas the type
xwhich is bound in the type signature, so
ahave the same type.
ex1 : x -> y -> x ex1 a b = temp : x temp = a a
temp : xrefers to the type
xin the outer scope.
To explicitly shadow a type variable in scope, the variable can be reintroduced in the inner scope by a `forall` binder, as follows:
ex2 : x -> y -> x ex2 a b = -- doesn’t refer to x in outer scope id : ∀ x . x -> x id v = v temp = id 42 id a
id : ∀ x . x -> x doesn’t refer to x in outer scope
Note that here the type variable
xin the type of
idgets instantiated to two different types. First
Function.id 42instantiates it to
a,instantiates it to the outer scope's type