diff --git a/common/Types.hs b/common/Types.hs index bf31e0a..2eb714f 100644 --- a/common/Types.hs +++ b/common/Types.hs @@ -32,7 +32,7 @@ module Types , leastGeneralSharedTypeRain - , Typed(..) + , ASTTypeable(..) ) where import Control.Monad.State @@ -54,10 +54,10 @@ import ShowCode import TypeSizes import Utils -class Typed a where +class ASTTypeable a where astTypeOf :: (CSMR m, Die m) => a -> m A.Type -instance Typed A.Type where +instance ASTTypeable A.Type where astTypeOf = return -- | Gets the 'A.SpecType' for a given 'A.Name' from the recorded types in the 'CompState'. Dies with an error if the name is unknown. @@ -70,13 +70,13 @@ abbrevModeOfName :: (CSMR m, Die m) => A.Name -> m A.AbbrevMode abbrevModeOfName n = liftM A.ndAbbrevMode (lookupNameOrError n $ dieP (A.nameMeta n) $ "Could not find abbreviation mode in abbrevModeOfName for: " ++ (show $ A.nameName n)) -instance Typed A.Name where +instance ASTTypeable A.Name where astTypeOf = typeOfName -instance Typed A.Formal where +instance ASTTypeable A.Formal where astTypeOf (A.Formal _ t _) = return t -instance Typed A.Actual where +instance ASTTypeable A.Actual where astTypeOf (A.ActualVariable v) = astTypeOf v astTypeOf (A.ActualExpression e) = astTypeOf e @@ -183,7 +183,7 @@ trivialSubscriptType _ (A.Array [d] t) = return t trivialSubscriptType _ (A.Array (d:ds) t) = return $ A.Array ds t trivialSubscriptType m t = diePC m $ formatCode "not plain array type: %" t -instance Typed A.Variable where +instance ASTTypeable A.Variable where astTypeOf = typeOfVariable -- | Gets the 'A.Type' of a 'A.Variable' by looking at the types recorded in the 'CompState'. @@ -219,7 +219,7 @@ dyadicIsBoolean A.MoreEq = True dyadicIsBoolean A.After = True dyadicIsBoolean _ = False -instance Typed A.Expression where +instance ASTTypeable A.Expression where astTypeOf = typeOfExpression -- | Gets the 'A.Type' of an 'A.Expression'. This function assumes that the expression has already been type-checked. diff --git a/frontends/RainTypes.hs b/frontends/RainTypes.hs index ef393d6..acbe4b6 100644 --- a/frontends/RainTypes.hs +++ b/frontends/RainTypes.hs @@ -77,7 +77,7 @@ typeToTypeExp _ (A.UnknownNumLitType m id n) return v typeToTypeExp m t = return $ OperType m (show t) (const t) [] -markUnify :: (Typed a, Typed b, Data a, Data b) => a -> b -> PassM () +markUnify :: (ASTTypeable a, ASTTypeable b, Data a, Data b) => a -> b -> PassM () markUnify x y = do tx <- astTypeOf x ty <- astTypeOf y