From 097dfcba775724fff22039d5895d44ac4d31d5fe Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 13 Apr 2016 12:06:21 +0200 Subject: [PATCH] replace ding in map' --- sem.icl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sem.icl b/sem.icl index ab7aa9c..1bedd62 100644 --- a/sem.icl +++ b/sem.icl @@ -129,7 +129,20 @@ instance unify Expr where where m = typeExpr e >>= \tex-> unify t tex replace :: String Type -> Env Void -replace _ _ = undef +replace ident type = get >>= \(st, fr)->put ('Map'.fromList $ + map (itupdate ident type) ('Map'.toList st), fr) + where + itupdate :: String Type (String, Type) -> (String, Type) + itupdate ident newtype ov=:(key, IdType type) = if (ident == type) + (key, newtype) ov + itupdate ident newtype (key, TupleType (t1, t2)) + # (_, t1) = itupdate ident newtype (key, t1) + # (_, t2) = itupdate ident newtype (key, t2) + = (key, TupleType (t1, t2)) + itupdate ident newtype (key, ListType t1) + # (_, t1) = itupdate ident newtype (key, t1) + = (key, ListType t1) + itupdate _ _ k = k instance unify Type where unify IntType IntType = pure IntType -- 2.20.1