Copyright | (c) Microsoft |
---|---|
License | MIT |
Maintainer | adamsap@microsoft.com |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell98 |
- isScalar :: Type -> Bool
- isUnsigned :: Type -> Bool
- isSigned :: Type -> Bool
- isFloat :: Type -> Bool
- isString :: Type -> Bool
- isContainer :: Type -> Bool
- isList :: Type -> Bool
- isAssociative :: Type -> Bool
- isNullable :: Type -> Bool
- isStruct :: Type -> Bool
- isEnum :: Type -> Bool
- isMetaName :: Type -> Bool
- fmapType :: (Type -> Type) -> Type -> Type
- foldMapFields :: Monoid m => (Field -> m) -> Type -> m
- foldMapStructFields :: Monoid m => (Field -> m) -> Declaration -> m
- foldMapType :: Monoid m => (Type -> m) -> Type -> m
- resolveAlias :: Declaration -> [Type] -> Type
Type classification
Functions that test if a type belongs to a particular category. These functions will resolve type aliases and return answer based on the type the alias resolves to.
isContainer :: Type -> Bool Source #
Returns True
if the type represents a container (i.e. list, vector, set or map).
isStruct :: Type -> Bool Source #
Returns True
if the type represents a struct or a struct forward declaration.
Type mapping
Folds
foldMapStructFields :: Monoid m => (Field -> m) -> Declaration -> m Source #
Like foldMapFields
but takes a Declaration
as an argument instead of Type
.
foldMapType :: Monoid m => (Type -> m) -> Type -> m Source #
Maps all parts of a Type
to a Monoid
and combines the results.
Examples
For a type:
list<nullable<int32>>
the result is:
f (BT_List (BT_Nullable BT_Int32)) <> f (BT_Nullable BT_Int32) <> f BT_Int32
foldMapType
resolves type aliases. E.g. given the following type alias
declaration (Bond IDL syntax):
using Array<T, N> = vector<T>;
the result for the following type:
Array<int32, 10>
is:
f (BT_UserDefined Alias{..} [BT_Int32, BT_IntTypeArg 10]) <> f (BT_Vector BT_Int32) <> f BT_Int32
Helper functions
resolveAlias :: Declaration -> [Type] -> Type Source #
Resolves a type alias declaration with given type arguments. Note that the function resolves one level of aliasing and thus may return a type alias.