ddc-core-0.4.1.3: Disciplined Disciple Compiler core language and type checker.

Safe HaskellSafe-Inferred

DDC.Type.DataDef

Contents

Description

Algebraic data type definitions.

Synopsis

Documentation

data DataDef n Source

The definition of a single data type.

Constructors

DataDef 

Fields

dataDefTypeName :: !n

Name of the data type.

dataDefParams :: ![Bind n]

Binders for type parameters.

dataDefCtors :: !(Maybe [DataCtor n])

Constructors of the data type, or Nothing if the data type is algbraic but there are too many constructors to list (like with Int).

dataDefIsAlgebraic :: Bool

Whether the data type is algebraic. These can be deconstructed with 'case' expressions.

Instances

SpreadT DataDef 
Show n => Show (DataDef n) 
(Pretty n, Eq n) => Pretty (DataDef n) 
NFData n => NFData (DataDef n) 

kindOfDataDef :: DataDef n -> Kind nSource

Get the kind of the type constructor defined by a DataDef.

dataTypeOfDataDef :: DataDef n -> Type nSource

Get the type associated with a data definition, that is, the type produced by the constructors.

dataCtorNamesOfDataDef :: DataDef n -> Maybe [n]Source

Get the list of data constructor names that this type defines, or Nothing if there are too many to list.

makeDataDefAlgSource

Arguments

:: n

Name of data type.

-> [Bind n]

Type parameters.

-> Maybe [(n, [Type n])]

Constructor names and field types, or Nothing if there are too many to list.

-> DataDef n 

Shortcut for constructing a DataDef for an algebraic type.

Values of algebraic type can be deconstructed with case-expressions.

makeDataDefAbs :: n -> [Bind n] -> DataDef nSource

Shortcut for constructing a DataDef for an abstract type.

Values of abstract type cannot be deconstructed with case-expressions.

Data type definition table

data DataDefs n Source

A table of data type definitions, unpacked into type and data constructors so we can find them easily.

Constructors

DataDefs 

Fields

dataDefsTypes :: !(Map n (DataType n))
 
dataDefsCtors :: !(Map n (DataCtor n))
 

Instances

SpreadT DataDefs 
Show n => Show (DataDefs n) 

data DataMode n Source

The mode of a data type records how many data constructors there are. This can be set to Large for large primitive types like Int and Float. In this case we don't ever expect them all to be enumerated as case alternatives.

Constructors

DataModeSmall ![n] 
DataModeLarge 

Instances

Show n => Show (DataMode n) 

emptyDataDefs :: DataDefs nSource

An empty table of data type definitions.

insertDataDef :: Ord n => DataDef n -> DataDefs n -> DataDefs nSource

Insert a data type definition into some DataDefs.

unionDataDefs :: Ord n => DataDefs n -> DataDefs n -> DataDefs nSource

Union two DataDef tables.

fromListDataDefs :: Ord n => [DataDef n] -> DataDefs nSource

Build a DataDefs table from a list of DataDef

data DataType n Source

Describes a data type constructor, used in the DataDefs table.

Constructors

DataType 

Fields

dataTypeName :: !n

Name of data type constructor.

dataTypeParams :: ![Bind n]

Kinds of type parameters to constructor.

dataTypeMode :: !(DataMode n)

Names of data constructors of this data type, or Nothing if it has infinitely many constructors.

dataTypeIsAlgebraic :: Bool

Whether the data type is algebraic.

Instances

SpreadT DataType 
Show n => Show (DataType n) 

kindOfDataType :: DataType n -> Kind nSource

Get the kind of the type constructor defined by a DataDef.

lookupModeOfDataType :: Ord n => n -> DataDefs n -> Maybe (DataMode n)Source

Yield the list of data constructor names for some data type, or Nothing for large types with too many constructors to list.

data DataCtor n Source

Describes a data constructor, used in the DataDefs table.

Constructors

DataCtor 

Fields

dataCtorName :: !n

Name of data constructor.

dataCtorTag :: !Integer

Tag of constructor (order in data type declaration)

dataCtorFieldTypes :: ![Type n]

Field types of constructor.

dataCtorResultType :: !(Type n)

Result type of constructor.

dataCtorTypeName :: !n

Name of result type of constructor.

dataCtorTypeParams :: ![Bind n]

Parameters of data type

Instances

SpreadT DataCtor 
Show n => Show (DataCtor n) 
(Pretty n, Eq n) => Pretty (DataCtor n) 
NFData n => NFData (DataCtor n) 

typeOfDataCtor :: DataCtor n -> Type nSource

Get the type of DataCtor