From: Mart Lubbers Date: Wed, 13 Apr 2016 10:06:21 +0000 (+0200) Subject: replace ding in map' X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=097dfcba775724fff22039d5895d44ac4d31d5fe;p=cc1516.git replace ding in map' --- 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