diff --git a/Interpreter.cs b/Interpreter.cs index a1ba45a..6edb57d 100644 --- a/Interpreter.cs +++ b/Interpreter.cs @@ -63,16 +63,6 @@ public class Env public class Interpreter : AST.IExprVisitor { - private static void checkTypesEqual(object a, object b) - { - var aType = a.GetType(); - var bType = b.GetType(); - if (aType != bType) - { - throw new Exception("Type mismatch: {aType} != {bType}."); - } - } - private class PatternMismatchException : Exception { public readonly Token Start; @@ -203,7 +193,6 @@ public class Interpreter : AST.IExprVisitor { throw new ArgumentException($"no such field: {name}"); } - checkTypesEqual(value, values.Peek()); return new Record { Fields = Fields.SetItem(name, values!.Pop().Push(value)) }; } @@ -470,13 +459,7 @@ public class Interpreter : AST.IExprVisitor List l = List.Empty; foreach (var itemExpr in expr.Elements) { - var item = evaluate(env, itemExpr); - if (!l.IsEmpty) - { - try { checkTypesEqual(l[0], item); } - catch { throw new RuntimeError(itemExpr.Start, "List items must all have same type."); } - } - l = l.Add(item); + l = l.Add(evaluate(env, itemExpr)); } return l; }