Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
A model for simple algebraic data types.
Synopsis
- data TypeModel adtName consName inRef exRef = TypeModel {}
- type TypeEnv adtName consName inRef exRef = Map exRef (ADT adtName consName inRef)
- typeADTs :: TypeModel adtName consName inRef k -> [ADT adtName consName inRef]
- data ADT name consName ref = ADT {}
- data ConTree name ref
- = Con {
- constrName :: name
- constrFields :: Fields name ref
- | ConTree (ConTree name ref) (ConTree name ref)
- = Con {
- type Fields name ref = Either [Type ref] [(name, Type ref)]
- data Type ref
- data TypeN r = TypeN r [TypeN r]
- nestedTypeNs :: TypeN t -> [TypeN t]
- data TypeRef name
- newtype Name = Name String
- data QualName = QualName {}
- qualName :: QualName -> String
- adtNamesMap :: (adtName1 -> adtName2) -> (consName1 -> consName2) -> ADT adtName1 consName1 ref -> ADT adtName2 consName2 ref
- typeN :: Type r -> TypeN r
- typeA :: TypeN ref -> Type ref
- contree :: [(name, Fields name ref)] -> Maybe (ConTree name ref)
- constructors :: ConTree name ref -> [(name, Fields name ref)]
- constructorInfo :: Eq consName => consName -> ConTree consName t -> Maybe ([Bool], [Type t])
- conTreeNameMap :: (name -> name2) -> ConTree name t -> ConTree name2 t
- conTreeNameFold :: Monoid a => (name -> a) -> ConTree name t -> a
- conTreeTypeMap :: (Type t -> Type ref) -> ConTree name t -> ConTree name ref
- conTreeTypeList :: ConTree name t -> [Type t]
- conTreeTypeFoldMap :: Monoid a => (Type t -> a) -> ConTree name t -> a
- fieldsTypes :: Either [b] [(a, b)] -> [b]
- fieldsNames :: Either t [(a, t1)] -> [t1]
- type HTypeEnv = TypeEnv String String (TypeRef QualName) QualName
- type HTypeModel = TypeModel String String (TypeRef QualName) QualName
- type HADT = ADT String String HTypeRef
- type HType = Type HTypeRef
- type HTypeRef = TypeRef QualName
- solve :: (Ord k, Show k) => k -> Map k a -> a
- solveAll :: (Functor f, Show k, Ord k) => Map k b -> f k -> f b
- unVar :: TypeRef t -> t
- getHRef :: TypeRef a -> Maybe a
- module GHC.Generics
- data Proxy (t :: k) :: forall k. k -> Type = Proxy
Model
data TypeModel adtName consName inRef exRef Source #
The complete model of a type, a reference to the type plus its environment:
- adtName: type used to represent the name of a data type
- consName: type used to represent the name of a constructor
- inRef: type used to represent a reference to a type or a type variable inside the data type definition (for example
HTypeRef
) - exRef: type used to represent a reference to a type in the type name (for example
QualName
)
Instances
(Eq exRef, Eq adtName, Eq consName, Eq inRef) => Eq (TypeModel adtName consName inRef exRef) Source # | |
(Ord exRef, Ord adtName, Ord consName, Ord inRef) => Ord (TypeModel adtName consName inRef exRef) Source # | |
Defined in Data.Model.Types compare :: TypeModel adtName consName inRef exRef -> TypeModel adtName consName inRef exRef -> Ordering # (<) :: TypeModel adtName consName inRef exRef -> TypeModel adtName consName inRef exRef -> Bool # (<=) :: TypeModel adtName consName inRef exRef -> TypeModel adtName consName inRef exRef -> Bool # (>) :: TypeModel adtName consName inRef exRef -> TypeModel adtName consName inRef exRef -> Bool # (>=) :: TypeModel adtName consName inRef exRef -> TypeModel adtName consName inRef exRef -> Bool # max :: TypeModel adtName consName inRef exRef -> TypeModel adtName consName inRef exRef -> TypeModel adtName consName inRef exRef # min :: TypeModel adtName consName inRef exRef -> TypeModel adtName consName inRef exRef -> TypeModel adtName consName inRef exRef # | |
(Show exRef, Show adtName, Show consName, Show inRef) => Show (TypeModel adtName consName inRef exRef) Source # | |
Generic (TypeModel adtName consName inRef exRef) Source # | |
(NFData exRef, NFData adtName, NFData consName, NFData inRef) => NFData (TypeModel adtName consName inRef exRef) Source # | |
Defined in Data.Model.Types | |
(Functor t, Pretty (t Name), Pretty exRef, Ord exRef, Show exRef, Convertible adtName String, Convertible consName String, Convertible iref String) => Pretty (TypeModel adtName consName (t iref) exRef) Source # | |
Defined in Data.Model.Pretty pPrintPrec :: PrettyLevel -> Rational -> TypeModel adtName consName (t iref) exRef -> Doc # pPrint :: TypeModel adtName consName (t iref) exRef -> Doc # pPrintList :: PrettyLevel -> [TypeModel adtName consName (t iref) exRef] -> Doc # | |
type Rep (TypeModel adtName consName inRef exRef) Source # | |
Defined in Data.Model.Types type Rep (TypeModel adtName consName inRef exRef) = D1 (MetaData "TypeModel" "Data.Model.Types" "model-0.5-9pTavxk2UCWIOTiByR8qw8" False) (C1 (MetaCons "TypeModel" PrefixI True) (S1 (MetaSel (Just "typeName") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Type exRef)) :*: S1 (MetaSel (Just "typeEnv") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (TypeEnv adtName consName inRef exRef)))) |
type TypeEnv adtName consName inRef exRef = Map exRef (ADT adtName consName inRef) Source #
A map of all the ADTs that are directly or indirectly referred by a type, indexed by a type reference
typeADTs :: TypeModel adtName consName inRef k -> [ADT adtName consName inRef] Source #
The ADTs defined in the TypeModel
data ADT name consName ref Source #
Simple algebraic data type (not a GADT):
- declName: type used to represent the name of the data type
- consName: type used to represent the name of a constructor
- ref: type used to represent a reference to a type or a type variable inside the data type definition (for example
HTypeRef
)
Instances
Functor (ADT name consName) Source # | |
Foldable (ADT name consName) Source # | |
Defined in Data.Model.Types fold :: Monoid m => ADT name consName m -> m # foldMap :: Monoid m => (a -> m) -> ADT name consName a -> m # foldr :: (a -> b -> b) -> b -> ADT name consName a -> b # foldr' :: (a -> b -> b) -> b -> ADT name consName a -> b # foldl :: (b -> a -> b) -> b -> ADT name consName a -> b # foldl' :: (b -> a -> b) -> b -> ADT name consName a -> b # foldr1 :: (a -> a -> a) -> ADT name consName a -> a # foldl1 :: (a -> a -> a) -> ADT name consName a -> a # toList :: ADT name consName a -> [a] # null :: ADT name consName a -> Bool # length :: ADT name consName a -> Int # elem :: Eq a => a -> ADT name consName a -> Bool # maximum :: Ord a => ADT name consName a -> a # minimum :: Ord a => ADT name consName a -> a # | |
Traversable (ADT name consName) Source # | |
Defined in Data.Model.Types traverse :: Applicative f => (a -> f b) -> ADT name consName a -> f (ADT name consName b) # sequenceA :: Applicative f => ADT name consName (f a) -> f (ADT name consName a) # mapM :: Monad m => (a -> m b) -> ADT name consName a -> m (ADT name consName b) # sequence :: Monad m => ADT name consName (m a) -> m (ADT name consName a) # | |
(Eq name, Eq consName, Eq ref) => Eq (ADT name consName ref) Source # | |
(Ord name, Ord consName, Ord ref) => Ord (ADT name consName ref) Source # | |
Defined in Data.Model.Types compare :: ADT name consName ref -> ADT name consName ref -> Ordering # (<) :: ADT name consName ref -> ADT name consName ref -> Bool # (<=) :: ADT name consName ref -> ADT name consName ref -> Bool # (>) :: ADT name consName ref -> ADT name consName ref -> Bool # (>=) :: ADT name consName ref -> ADT name consName ref -> Bool # max :: ADT name consName ref -> ADT name consName ref -> ADT name consName ref # min :: ADT name consName ref -> ADT name consName ref -> ADT name consName ref # | |
(Show name, Show consName, Show ref) => Show (ADT name consName ref) Source # | |
Generic (ADT name consName ref) Source # | |
(NFData name, NFData consName, NFData ref) => NFData (ADT name consName ref) Source # | |
Defined in Data.Model.Types | |
(Pretty n, Pretty cn, Pretty r) => Pretty (ADT n cn r) Source # | |
Defined in Data.Model.Pretty pPrintPrec :: PrettyLevel -> Rational -> ADT n cn r -> Doc # pPrintList :: PrettyLevel -> [ADT n cn r] -> Doc # | |
type Rep (ADT name consName ref) Source # | |
Defined in Data.Model.Types type Rep (ADT name consName ref) = D1 (MetaData "ADT" "Data.Model.Types" "model-0.5-9pTavxk2UCWIOTiByR8qw8" False) (C1 (MetaCons "ADT" PrefixI True) (S1 (MetaSel (Just "declName") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 name) :*: (S1 (MetaSel (Just "declNumParameters") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Word8) :*: S1 (MetaSel (Just "declCons") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe (ConTree consName ref)))))) |
data ConTree name ref Source #
Constructors are assembled in a binary tree
Con | |
| |
ConTree (ConTree name ref) (ConTree name ref) | Constructor tree. Constructors are disposed in an optimally balanced, right heavier tree: For example, the data type: data N = One | Two | Three | Four | Five Would have its contructors ordered in the following tree: | | | One Two Three | Four Five To get a list of constructor in declaration order, use |
Instances
Functor (ConTree name) Source # | |
Foldable (ConTree name) Source # | |
Defined in Data.Model.Types fold :: Monoid m => ConTree name m -> m # foldMap :: Monoid m => (a -> m) -> ConTree name a -> m # foldr :: (a -> b -> b) -> b -> ConTree name a -> b # foldr' :: (a -> b -> b) -> b -> ConTree name a -> b # foldl :: (b -> a -> b) -> b -> ConTree name a -> b # foldl' :: (b -> a -> b) -> b -> ConTree name a -> b # foldr1 :: (a -> a -> a) -> ConTree name a -> a # foldl1 :: (a -> a -> a) -> ConTree name a -> a # toList :: ConTree name a -> [a] # null :: ConTree name a -> Bool # length :: ConTree name a -> Int # elem :: Eq a => a -> ConTree name a -> Bool # maximum :: Ord a => ConTree name a -> a # minimum :: Ord a => ConTree name a -> a # | |
Traversable (ConTree name) Source # | |
Defined in Data.Model.Types | |
(Eq name, Eq ref) => Eq (ConTree name ref) Source # | |
(Ord name, Ord ref) => Ord (ConTree name ref) Source # | |
Defined in Data.Model.Types compare :: ConTree name ref -> ConTree name ref -> Ordering # (<) :: ConTree name ref -> ConTree name ref -> Bool # (<=) :: ConTree name ref -> ConTree name ref -> Bool # (>) :: ConTree name ref -> ConTree name ref -> Bool # (>=) :: ConTree name ref -> ConTree name ref -> Bool # max :: ConTree name ref -> ConTree name ref -> ConTree name ref # min :: ConTree name ref -> ConTree name ref -> ConTree name ref # | |
(Show name, Show ref) => Show (ConTree name ref) Source # | |
Generic (ConTree name ref) Source # | |
(NFData name, NFData ref) => NFData (ConTree name ref) Source # | |
Defined in Data.Model.Types | |
(Pretty name, Pretty ref) => Pretty (ConTree name ref) Source # | |
Defined in Data.Model.Pretty pPrintPrec :: PrettyLevel -> Rational -> ConTree name ref -> Doc # pPrint :: ConTree name ref -> Doc # pPrintList :: PrettyLevel -> [ConTree name ref] -> Doc # | |
type Rep (ConTree name ref) Source # | |
Defined in Data.Model.Types type Rep (ConTree name ref) = D1 (MetaData "ConTree" "Data.Model.Types" "model-0.5-9pTavxk2UCWIOTiByR8qw8" False) (C1 (MetaCons "Con" PrefixI True) (S1 (MetaSel (Just "constrName") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 name) :*: S1 (MetaSel (Just "constrFields") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Fields name ref))) :+: C1 (MetaCons "ConTree" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ConTree name ref)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ConTree name ref)))) |
A type
Instances
Another representation of a type, sometime easier to work with
Instances
nestedTypeNs :: TypeN t -> [TypeN t] Source #
Returns the list of nested TypeNs
>>>
nestedTypeNs $ TypeN "F" [TypeN "G" [],TypeN "Z" []]
[TypeN "F" [TypeN "G" [],TypeN "Z" []],TypeN "G" [],TypeN "Z" []]
>>>
nestedTypeNs $ TypeN "F" [TypeN "G" [TypeN "H" [TypeN "L" []]],TypeN "Z" []]
[TypeN "F" [TypeN "G" [TypeN "H" [TypeN "L" []]],TypeN "Z" []],TypeN "G" [TypeN "H" [TypeN "L" []]],TypeN "H" [TypeN "L" []],TypeN "L" [],TypeN "Z" []]
A reference to a type
Instances
Names
Simple name
Instances
Eq Name Source # | |
Ord Name Source # | |
Show Name Source # | |
Generic Name Source # | |
NFData Name Source # | |
Defined in Data.Model.Types | |
Pretty Name Source # | |
Defined in Data.Model.Pretty pPrintPrec :: PrettyLevel -> Rational -> Name -> Doc # pPrintList :: PrettyLevel -> [Name] -> Doc # | |
type Rep Name Source # | |
Defined in Data.Model.Types |
A fully qualified Haskell name
Instances
qualName :: QualName -> String Source #
Return the qualified name, minus the package name.
>>>
qualName (QualName {pkgName = "ab", mdlName = "cd.ef", locName = "gh"})
"cd.ef.gh"
Model Utilities
adtNamesMap :: (adtName1 -> adtName2) -> (consName1 -> consName2) -> ADT adtName1 consName1 ref -> ADT adtName2 consName2 ref Source #
Map over the names of an ADT and of its constructors
contree :: [(name, Fields name ref)] -> Maybe (ConTree name ref) Source #
Convert a (possibly empty) list of constructors in (maybe) a ConTree
constructors :: ConTree name ref -> [(name, Fields name ref)] Source #
Return the list of constructors in definition order
constructorInfo :: Eq consName => consName -> ConTree consName t -> Maybe ([Bool], [Type t]) Source #
Return the binary encoding and parameter types of a constructor
The binary encoding is the sequence of Left (False) and Right (True) turns needed to reach the constructor from the constructor tree root
conTreeNameMap :: (name -> name2) -> ConTree name t -> ConTree name2 t Source #
Map over a constructor tree names
conTreeNameFold :: Monoid a => (name -> a) -> ConTree name t -> a Source #
Fold over a constructor tree names
conTreeTypeMap :: (Type t -> Type ref) -> ConTree name t -> ConTree name ref Source #
Map on the constructor types (used for example when eliminating variables)
conTreeTypeList :: ConTree name t -> [Type t] Source #
Extract list of types in a constructor tree
conTreeTypeFoldMap :: Monoid a => (Type t -> a) -> ConTree name t -> a Source #
Fold over the types in a constructor tree
fieldsTypes :: Either [b] [(a, b)] -> [b] Source #
Return just the field types
fieldsNames :: Either t [(a, t1)] -> [t1] Source #
Return just the field names (or an empty list if unspecified)
Handy aliases
Utilities
solve :: (Ord k, Show k) => k -> Map k a -> a Source #
Solve a key in an environment, returns an error if the key is missing
solveAll :: (Functor f, Show k, Ord k) => Map k b -> f k -> f b Source #
Solve all references in a data structure, using the given environment
unVar :: TypeRef t -> t Source #
Remove variable references (for example if we know that a type is fully saturated and cannot contain variables)
Re-exports
module GHC.Generics
data Proxy (t :: k) :: forall k. k -> Type #
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a'undefined :: a'
idiom.
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Generic1 (Proxy :: k -> Type) | |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Eq1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Ord1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
NFData1 (Proxy :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Ix (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
NFData (Proxy a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
type Rep (Proxy t) | Since: base-4.6.0.0 |