48 |
48 |
49 def typ: T[Typ] = |
49 def typ: T[Typ] = |
50 variant[Typ](List( |
50 variant[Typ](List( |
51 { case (List(a), b) => Type(a, list(typ)(b)) case _ => ??? }, |
51 { case (List(a), b) => Type(a, list(typ)(b)) case _ => ??? }, |
52 { case (List(a), b) => TFree(a, sort(b)) case _ => ??? }, |
52 { case (List(a), b) => TFree(a, sort(b)) case _ => ??? }, |
53 { case (a, b) => TVar(indexname(a), sort(b)) case _ => ??? })) |
53 { case (a, b) => TVar(indexname(a), sort(b)) })) |
54 |
54 |
55 val typ_body: T[Typ] = { case Nil => dummyT case body => typ(body) } |
55 val typ_body: T[Typ] = { case Nil => dummyT case body => typ(body) } |
56 |
56 |
57 def term: T[Term] = |
57 def term: T[Term] = |
58 variant[Term](List( |
58 variant[Term](List( |
59 { case (List(a), b) => Const(a, list(typ)(b)) case _ => ??? }, |
59 { case (List(a), b) => Const(a, list(typ)(b)) case _ => ??? }, |
60 { case (List(a), b) => Free(a, typ_body(b)) case _ => ??? }, |
60 { case (List(a), b) => Free(a, typ_body(b)) case _ => ??? }, |
61 { case (a, b) => Var(indexname(a), typ_body(b)) case _ => ??? }, |
61 { case (a, b) => Var(indexname(a), typ_body(b)) }, |
62 { case (Nil, a) => Bound(int(a)) case _ => ??? }, |
62 { case (Nil, a) => Bound(int(a)) case _ => ??? }, |
63 { case (List(a), b) => val (c, d) = pair(typ, term)(b); Abs(a, c, d) case _ => ??? }, |
63 { case (List(a), b) => val (c, d) = pair(typ, term)(b); Abs(a, c, d) case _ => ??? }, |
64 { case (Nil, a) => val (b, c) = pair(term, term)(a); App(b, c) case _ => ??? })) |
64 { case (Nil, a) => val (b, c) = pair(term, term)(a); App(b, c) case _ => ??? })) |
65 |
65 |
66 def term_env(env: Map[String, Typ]): T[Term] = { |
66 def term_env(env: Map[String, Typ]): T[Term] = { |
69 |
69 |
70 def term: T[Term] = |
70 def term: T[Term] = |
71 variant[Term](List( |
71 variant[Term](List( |
72 { case (List(a), b) => Const(a, list(typ)(b)) case _ => ??? }, |
72 { case (List(a), b) => Const(a, list(typ)(b)) case _ => ??? }, |
73 { case (List(a), b) => Free(a, env_type(a, typ_body(b))) case _ => ??? }, |
73 { case (List(a), b) => Free(a, env_type(a, typ_body(b))) case _ => ??? }, |
74 { case (a, b) => Var(indexname(a), typ_body(b)) case _ => ??? }, |
74 { case (a, b) => Var(indexname(a), typ_body(b)) }, |
75 { case (Nil, a) => Bound(int(a)) case _ => ??? }, |
75 { case (Nil, a) => Bound(int(a)) case _ => ??? }, |
76 { case (List(a), b) => val (c, d) = pair(typ, term)(b); Abs(a, c, d) case _ => ??? }, |
76 { case (List(a), b) => val (c, d) = pair(typ, term)(b); Abs(a, c, d) case _ => ??? }, |
77 { case (Nil, a) => val (b, c) = pair(term, term)(a); App(b, c) case _ => ??? })) |
77 { case (Nil, a) => val (b, c) = pair(term, term)(a); App(b, c) case _ => ??? })) |
78 term |
78 term |
79 } |
79 } |