From 19ca657d6b247c1acab1329ccf0c54d896178c87 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Tue, 15 May 2012 01:06:39 +1000 Subject: Fixed a number of compilation errors --- Parse.hs | 13 ++++++++++++- Term.hs | 19 +++++++++++-------- TypeVar.hs | 9 ++++++--- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Parse.hs b/Parse.hs index 769a883..484342f 100644 --- a/Parse.hs +++ b/Parse.hs @@ -1,3 +1,14 @@ +module Parse ( + getLines, + stripReturn, + removeEscChars, + removeQuotes, + separateBy, + isComment, + isNumber, + isName + ) where + import Control.Monad( liftM ) import qualified Data.Char as Char @@ -22,7 +33,7 @@ removeQuotes :: String -> String removeQuotes = init . tail -separateBy :: String -> Char -> [String] +separateBy :: Char -> String -> [String] separateBy char list = let f = (\x -> if (x == char) then ' ' diff --git a/Term.hs b/Term.hs index 444ae1a..9fdd84d 100644 --- a/Term.hs +++ b/Term.hs @@ -5,9 +5,11 @@ module Term ( alphaConvert, alphaConvertList, substitute, - containsVars, + boundVars, + freeVars, rename, typeOf, + typeVarsInTerm, mkEquals, isEq, getlhs, @@ -16,6 +18,7 @@ module Term ( +import Data.List import qualified Data.Set as Set import TypeVar @@ -108,21 +111,21 @@ substitute (tymap,vmap) term = in vdone -boundVars :: Term -> Set Var +boundVars :: Term -> Set.Set Var boundVars (TConst a b) = Set.empty boundVars (TApp a b) = Set.union (boundVars a) (boundVars b) boundVars (TVar a) = Set.empty -boundVars (TAbs a b) = Set.insert a (boundVars b) +boundVars (TAbs a b) = Set.insert (tVar a) (boundVars b) -freeVars :: Term -> Set Var +freeVars :: Term -> Set.Set Var freeVars (TConst a b) = Set.empty freeVars (TApp a b) = Set.union (freeVars a) (freeVars b) freeVars (TVar a) = Set.singleton a -freeVars (TAbs a b) = Set.delete a (freeVars b) +freeVars (TAbs a b) = Set.delete (tVar a) (freeVars b) -rename :: Term -> Set Var -> Term +rename :: Term -> Set.Set Var -> Term rename (TAbs (TVar v) t) vars = let doRename = (\x y z -> case x of @@ -155,10 +158,10 @@ typeOf (TApp f _) = last . aType . typeOf $ f -typeVarsInTerm :: Term -> Set Type +typeVarsInTerm :: Term -> Set.Set Type typeVarsInTerm (TConst _ ty) = typeVarsInType ty typeVarsInTerm (TVar v) = typeVarsInType . varTy $ v -typeVarsInTerm (TAbs v t) = Set.union (typeVarsInType . varTy $ v) (typeVarsInTerm t) +typeVarsInTerm (TAbs v t) = Set.union (typeVarsInType . varTy . tVar $ v) (typeVarsInTerm t) typeVarsInTerm (TApp f x) = Set.union (typeVarsInTerm f) (typeVarsInTerm x) diff --git a/TypeVar.hs b/TypeVar.hs index 6196d63..329caf6 100644 --- a/TypeVar.hs +++ b/TypeVar.hs @@ -12,12 +12,15 @@ module TypeVar ( Var(..), mkEqualsType, - typeFunc + typeFunc, + typeBool, + typeVarsInType ) where import Data.List +import qualified Data.Set as Set @@ -69,6 +72,6 @@ typeBool :: Type typeBool = AType [] (TypeOp (Name [] "bool")) -typeVarsInType :: Type -> Set Type +typeVarsInType :: Type -> Set.Set Type typeVarsInType (TypeVar t) = Set.singleton (TypeVar t) -typeVarsInType (AType list _) = unions . (map typeVarsInType) $ list +typeVarsInType (AType list _) = Set.unions . (map typeVarsInType) $ list -- cgit