# Path: types_builtin.py
# def app_map(data, appTs):
#     apps = {}
#     for tv, at in ezip(data.tvars, appTs):
#         if isinstance(at, TVar) and at.typeVar is tv:
#             continue
#         apps[tv] = at
#     return apps
# 
# def subst(mapping, t):
#     return map_type_vars(lambda st: mapping.get(st.typeVar, st), t)


from base import *
from globs import *
from types_builtin import app_map, subst
            if not isinstance(ft, TWeak):
                val = getattr(obj, fnm)
                setattr(obj, fnm, mutate_by_type(val, ft))
        return obj
    elif cls is TArray:
        et = t.elemType
        assert isinstance(obj, list)
        if isinstance(et, TWeak):
            return obj
        return [mutate_by_type(o, et) for o in obj]
    else:
        assert False, "Bad type to mutate: %r" % (t,)

# COMBINATORIAL EXPLOSIONS

REIFIED_MONOTYPES = {}

def cement_type(t):
    key = type_key(t)
    if key in CONCRETE_TYPES:
        return CONCRETE_TYPES[key]
    else:
        assert False

def type_key(t):
    m = match(t)
    if m('TPrim(prim)'):
        return prim_key(m.prim)
    elif m('TData(dt, ts)'):
        nm = extrinsic(Name, dt)

# Path: types_builtin.py
# def app_map(data, appTs):
#     apps = {}
#     for tv, at in ezip(data.tvars, appTs):
#         if isinstance(at, TVar) and at.typeVar is tv:
#             continue
#         apps[tv] = at
#     return apps
# 
# def subst(mapping, t):
#     return map_type_vars(lambda st: mapping.get(st.typeVar, st), t)


# Path: vat.py
from base import *
from globs import *
from types_builtin import app_map, subst

            if not isinstance(ft, TWeak):
                val = getattr(obj, fnm)
                setattr(obj, fnm, mutate_by_type(val, ft))
        return obj
    elif cls is TArray:
        et = t.elemType
        assert isinstance(obj, list)
        if isinstance(et, TWeak):
            return obj
        return [mutate_by_type(o, et) for o in obj]
    else:
        assert False, "Bad type to mutate: %r" % (t,)

# COMBINATORIAL EXPLOSIONS

REIFIED_MONOTYPES = {}

def cement_type(t):
    key = type_key(t)
    if key in CONCRETE_TYPES:
        return CONCRETE_TYPES[key]
    else:
        assert False

def type_key(t):
    m = match(t)
    if m('TPrim(prim)'):
        return prim_key(m.prim)
    elif m('TData(dt, ts)'):
        nm = extrinsic(Name, dt)

        return '%s(%s)' % (nm, ', '.join(type_key(a) for a in m.ts))