Data.Typed

lib/Data/Typed.gob

No module comment.

type TypeRep = TypeRep(String, Prim.Array TypeRep)

A type, as a value: the constructor's qualified name and its arguments.

The name is TCon.name, which is module-qualified and which type_key, match and unification already compare. So equality of two reps is equality of two types, and cast needs no notion of identity the compiler does not already use for everything else.

The arguments are a Prim.Array rather than a Data.Array.Array because that is what the compiler builds most cheaply: a synthesized instance writes one directly as Core.

type Proxy a = Proxy

A type named without a value of it. typeRep has to mention a somewhere in its signature or no call could say which instance it wanted; Proxy is the argument that does that and carries nothing.

class Typed a

A type as a value, so that a packed payload can be asked what it is.

Instances are derived by the solver and a program may not write one: a hand-written instance could claim any type for any value, which is exactly what makes an unchecked cast unsound.

fun typeRep : [Typed a] fun(Proxy a) -> TypeRep
fun name : fun(TypeRep) -> String

What a type is called: the module-qualified constructor name, so two reps are equal exactly when the types they describe are.

fun arity : fun(TypeRep) -> Int
fun argument : fun(TypeRep, Int) -> TypeRep

The rep of one type argument. Out of range panics, as indexing does.

fun describe : fun(TypeRep) -> String

An argument that takes arguments of its own is parenthesized, because Pair Box Int String and Pair (Box Int) String are different types and a rendering that cannot tell them apart is worse than no rendering.

instance Show TypeRep
instance Eq TypeRep

Structural, because that is what type identity is: the same constructor applied to the same arguments. A cast compares these and converts nothing unless they agree.