This module contains the building blocks of types in the Morphir IR.
An opaque representation of a type. Check out the docs for each building blocks for more details:
variable : a -> Morphir.IR.Name.Name -> Type a
Creates a type variable.
toIR a == variable [ "a" ] ()
toIR fooBar == variable [ "foo", "bar" ] ()
reference : a -> Morphir.IR.FQName.FQName -> List (Type a) -> Type a
Creates a fully-qualified reference to a type.
toIR (List Int)
== reference SDK.List.listType [ intType ]
toIR Foo.Bar
== reference
( [ [ "my" ], [ "lib" ] ], [ [ "foo" ] ], [ "bar" ] )
[]
tuple : a -> List (Type a) -> Type a
Creates a tuple type.
toIR ( Int, Bool )
== tuple [ basic intType, basic boolType ]
record : a -> List (Field a) -> Type a
Creates a record type.
toIR {} == record []
toIR { foo = Int }
== record
[ field [ "foo" ] SDK.Basics.intType
]
toIR { foo = Int, bar = Bool }
== record
[ field [ "foo" ] SDK.Basics.intType
, field [ "bar" ] SDK.Basics.boolType
]
extensibleRecord : a -> Morphir.IR.Name.Name -> List (Field a) -> Type a
Creates an extensible record type.
toIR { e | foo = Int }
== extensibleRecord (variable [ "e" ])
[ field [ "foo" ] intType
]
toIR { f | foo = Int, bar = Bool }
== extensibleRecord (variable [ "f" ])
[ field [ "foo" ] intType
, field [ "bar" ] boolType
]
function : a -> Type a -> Type a -> Type a
Creates a function type. Use currying to create functions with more than one argument.
toIR (Int -> Bool) ==
function
SDK.Basics.intType
SDK.Basics.boolType
toIR (Int -> Bool -> Char) ==
function
intType
(function
SDK.Basics.boolType
SDK.Basics.charType
)
unit : a -> Type a
Creates a unit type.
toIR () == unit
{ name : Morphir.IR.Name.Name
, tpe : Type a
}
An opaque representation of a field. It's made up of a name and a type.
mapFieldName : (Morphir.IR.Name.Name -> Morphir.IR.Name.Name) -> Field a -> Field a
Map the name of the field to get a new field.
mapFieldType : (Type a -> Type b) -> Field a -> Field b
Map the type of the field to get a new field.
typeAliasSpecification : List Morphir.IR.Name.Name -> Type a -> Specification a
opaqueTypeSpecification : List Morphir.IR.Name.Name -> Specification a
customTypeSpecification : List Morphir.IR.Name.Name -> Constructors a -> Specification a
This syntax represents a type definition. For example:
type alias Foo a = {bar : Maybe a, qux : Int}
type MyList a = End | Cons a (MyList a)
In the definition, the List Name
refers to type parameters on the LHS
and Type extra
refers to the RHS
typeAliasDefinition : List Morphir.IR.Name.Name -> Type a -> Definition a
customTypeDefinition : List Morphir.IR.Name.Name -> Morphir.IR.AccessControlled.AccessControlled (Constructors a) -> Definition a
definitionToSpecification : Definition a -> Specification a
List (Constructor a)
mapTypeAttributes : (a -> b) -> Type a -> Type b
mapSpecificationAttributes : (a -> b) -> Specification a -> Specification b
mapDefinitionAttributes : (a -> b) -> Definition a -> Definition b
mapDefinition : (Type a -> Result e (Type b)) -> Definition a -> Result (List e) (Definition b)
eraseAttributes : Definition a -> Definition ()