Added a function to the Types module to allow you to easily change the type of a SpecType

This commit is contained in:
Neil Brown 2009-03-19 15:13:00 +00:00
parent 26824883d6
commit ca61da25cf

View File

@ -19,7 +19,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
-- | Type inference and checking. -- | Type inference and checking.
module Types module Types
( (
specTypeOfName, typeOfSpec, abbrevModeOfName, underlyingType, stripArrayType, abbrevModeOfVariable, abbrevModeOfSpec specTypeOfName, typeOfSpec, typeOfSpec', abbrevModeOfName, underlyingType, stripArrayType, abbrevModeOfVariable, abbrevModeOfSpec
, isRealType, isIntegerType, isNumericType, isCaseableType, isScalarType, isDataType, isCommunicableType, isSequenceType , isRealType, isIntegerType, isNumericType, isCaseableType, isScalarType, isDataType, isCommunicableType, isSequenceType
, resolveUserType, isSafeConversion, isPreciseConversion, isImplicitConversionRain , resolveUserType, isSafeConversion, isPreciseConversion, isImplicitConversionRain
, returnTypesOfFunction , returnTypesOfFunction
@ -91,23 +91,30 @@ typeOfName n
Nothing -> dieP (findMeta n) $ "cannot type name " ++ pshow n ++ Nothing -> dieP (findMeta n) $ "cannot type name " ++ pshow n ++
":" ++ show st ":" ++ show st
typeOfSpec :: (CSMR m, Die m) => A.SpecType -> m (Maybe A.Type) typeOfSpec' :: (CSMR m, Die m) => A.SpecType -> m (Maybe (A.Type, A.Type -> A.SpecType))
typeOfSpec st typeOfSpec' st
= case st of = case st of
A.Declaration _ t -> return $ Just t A.Declaration a t -> return $ Just (t, A.Declaration a)
A.Is _ _ t _ -> return $ Just t A.Is a b t c -> return $ Just (t, \t' -> A.Is a b t' c)
A.IsExpr _ _ t _ -> return $ Just t A.IsExpr a b t c -> return $ Just (t, \t' -> A.IsExpr a b t' c)
A.IsChannelArray _ t _ -> return $ Just t A.IsChannelArray a t b
A.Retypes _ _ t _ -> return $ Just t -> return $ Just (t, \t' -> A.IsChannelArray a t' b)
A.RetypesExpr _ _ t _ -> return $ Just t A.Retypes a b t c -> return $ Just (t, \t' -> A.Retypes a b t' c)
A.Rep _ (A.For _ _ e _) -> astTypeOf e >>* Just A.RetypesExpr a b t c
A.Rep _ (A.ForEach _ e) -> do t <- astTypeOf e -> return $ Just (t, \t' -> A.RetypesExpr a b t' c)
case t of A.Rep _ (A.For _ _ e _) -> do t <- astTypeOf e
A.List t' -> return $ Just t' return $ Just (t, error "typeOfSpec'")
A.Array _ t' -> return $ Just t' A.Rep _ (A.ForEach _ e) ->
_ -> return Nothing do t <- astTypeOf e
case t of
A.List t' -> return $ Just (t', error "typeOfSpec'")
A.Array _ t' -> return $ Just (t', error "typeOfSpec'")
_ -> return Nothing
_ -> return Nothing _ -> return Nothing
typeOfSpec :: (CSMR m, Die m) => A.SpecType -> m (Maybe A.Type)
typeOfSpec = liftM (fmap fst) . typeOfSpec'
--{{{ identifying types --{{{ identifying types
-- | Get the fields of a record type. -- | Get the fields of a record type.
recordFields :: (CSMR m, Die m) => Meta -> A.Type -> m [(A.Name, A.Type)] recordFields :: (CSMR m, Die m) => Meta -> A.Type -> m [(A.Name, A.Type)]