Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Library._
- object Desugar {
- def desugarList(es: List[ExprExt]): ExprC = es match {
- case h :: t => ConsC(desugar(h), desugarList(t))
- case _ => NilC()
- }
- def makeList(rows: List[ExprC]): ExprC = rows match {
- case rowList :: t => ConsC(rowList, makeList(t))
- case Nil => NilC()
- }
- def desugarListMultiply(matrixC: ExprC, number: ExprC): ExprC = matrixC match {
- case ConsC(h, t) => ConsC(MultC(h, number), desugarListMultiply(t, number))
- case _ => NilC()
- }
- def desugar(e: ExprExt): ExprC = e match {
- case NumExt(n) => NumC(n)
- case PlusExt(e1, e2) => PlusC(desugar(e1), desugar(e2))
- case MultExt(e1, e2) => MultC(desugar(e1), desugar(e2))
- case FdExt(x, e) => FdC(x, desugar(e))
- case AppExt(f, a) => AppC(desugar(f), desugar(a))
- case IdExt(x) => IdC(x)
- case ConsExt(h, t) => ConsC(desugar(h), desugar(t))
- case NilExt() => NilC()
- case ListExt(es) =>
- desugarList(es)
- case ListMapExt(f, l) =>
- ListMapC(desugar(f), desugar(l))
- case MatrixExt(rs) =>
- val rows: List[ExprC] = rs.map(row => row match {
- case RowExt(es) => desugarList(es)
- })
- makeList(rows)
- case ScalarMultExt(n, m) => ???
- }
- }
- //Expected ConsV(ConsV(NumV(3),ConsV(NumV(6),ConsV(NumV(9),NilV()))),ConsV(ConsV(NumV(12),ConsV(NumV(15),ConsV(NumV(18),NilV()))),NilV())),
- // but got ConsV(ConsV(NumV(3),ConsV(NumV(2),ConsV(NumV(3),NilV()))),ConsV(ConsV(NumV(12),ConsV(NumV(5),ConsV(NumV(6),NilV()))),NilV()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement