License | BSD-3-Clause |
---|---|
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Swarm.Language.Types
Description
Types for the Swarm programming language and related utilities.
Synopsis
- data BaseTy
- baseTyName :: BaseTy -> Text
- data TyCon
- newtype Arity = Arity {}
- tcArity :: TDCtx -> TyCon -> Maybe Arity
- type Var = Text
- data TypeF t
- data Nat where
- natToInt :: Nat -> Int
- unfoldRec :: SubstRec t => Var -> t -> t
- class SubstRec t where
- type Type = Fix TypeF
- tyVars :: Type -> Set Var
- pattern TyConApp :: TyCon -> [Type] -> Type
- pattern TyBase :: BaseTy -> Type
- pattern TyVar :: Var -> Type
- pattern TyVoid :: Type
- pattern TyUnit :: Type
- pattern TyInt :: Type
- pattern TyText :: Type
- pattern TyDir :: Type
- pattern TyBool :: Type
- pattern TyActor :: Type
- pattern TyKey :: Type
- pattern (:+:) :: Type -> Type -> Type
- pattern (:*:) :: Type -> Type -> Type
- pattern (:->:) :: Type -> Type -> Type
- pattern TyRcd :: Map Var Type -> Type
- pattern TyCmd :: Type -> Type
- pattern TyDelay :: Type -> Type
- pattern TyUser :: Var -> [Type] -> Type
- pattern TyRec :: Var -> Type -> Type
- newtype IntVar = IntVar Int
- type UType = Free TypeF IntVar
- pattern UTyConApp :: TyCon -> [UType] -> UType
- pattern UTyBase :: BaseTy -> UType
- pattern UTyVar :: Var -> UType
- pattern UTyVoid :: UType
- pattern UTyUnit :: UType
- pattern UTyInt :: UType
- pattern UTyText :: UType
- pattern UTyDir :: UType
- pattern UTyBool :: UType
- pattern UTyActor :: UType
- pattern UTyKey :: UType
- pattern UTySum :: UType -> UType -> UType
- pattern UTyProd :: UType -> UType -> UType
- pattern UTyFun :: UType -> UType -> UType
- pattern UTyRcd :: Map Var UType -> UType
- pattern UTyCmd :: UType -> UType
- pattern UTyDelay :: UType -> UType
- pattern UTyUser :: Var -> [UType] -> UType
- pattern UTyRec :: Var -> UType -> UType
- ucata :: Functor t => (v -> a) -> (t a -> a) -> Free t v -> a
- mkVarName :: Text -> IntVar -> Var
- fuvs :: UType -> Set IntVar
- data Poly t = Forall {}
- type Polytype = Poly Type
- pattern PolyUnit :: Polytype
- type UPolytype = Poly UType
- type TCtx = Ctx Polytype
- type UCtx = Ctx UPolytype
- data TydefInfo = TydefInfo {}
- tydefType :: Lens' TydefInfo Polytype
- tydefArity :: Lens' TydefInfo Arity
- substTydef :: forall t. Typical t => TydefInfo -> [t] -> t
- expandTydef :: (Has (Reader TDCtx) sig m, Typical t) => Var -> [t] -> m t
- elimTydef :: forall t. Typical t => Var -> TydefInfo -> t -> t
- type TDCtx = Ctx TydefInfo
- whnfType :: TDCtx -> Type -> Type
- class WithU t where
Basic definitions
Base types and type constructors
Base types.
Constructors
BVoid | The void type, with no inhabitants. |
BUnit | The unit type, with a single inhabitant. |
BInt | Signed, arbitrary-size integers. |
BText | Unicode strings. |
BDir | Directions. |
BBool | Booleans. |
BActor | Actors, i.e. anything that can do stuff. Internally, these are all just "robots", but we give them a more generic in-game name because they could represent other things like aliens, animals, seeds, ... |
BKey | Keys, i.e. things that can be pressed on the keyboard |
Instances
FromJSON BaseTy Source # | |
Defined in Swarm.Language.Types | |
ToJSON BaseTy Source # | |
Data BaseTy Source # | |
Defined in Swarm.Language.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> BaseTy -> c BaseTy # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c BaseTy # toConstr :: BaseTy -> Constr # dataTypeOf :: BaseTy -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c BaseTy) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BaseTy) # gmapT :: (forall b. Data b => b -> b) -> BaseTy -> BaseTy # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BaseTy -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BaseTy -> r # gmapQ :: (forall d. Data d => d -> u) -> BaseTy -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> BaseTy -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> BaseTy -> m BaseTy # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> BaseTy -> m BaseTy # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> BaseTy -> m BaseTy # | |
Bounded BaseTy Source # | |
Enum BaseTy Source # | |
Defined in Swarm.Language.Types | |
Generic BaseTy Source # | |
Show BaseTy Source # | |
Eq BaseTy Source # | |
Ord BaseTy Source # | |
PrettyPrec BaseTy Source # | |
Defined in Swarm.Language.Pretty | |
type Rep BaseTy Source # | |
Defined in Swarm.Language.Types type Rep BaseTy = D1 ('MetaData "BaseTy" "Swarm.Language.Types" "swarm-0.6.0.0-ERx1HMcRMba59aI2b6aNrS-swarm-lang" 'False) (((C1 ('MetaCons "BVoid" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BUnit" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "BInt" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BText" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "BDir" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BBool" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "BActor" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BKey" 'PrefixI 'False) (U1 :: Type -> Type)))) |
baseTyName :: BaseTy -> Text Source #
Type constructors.
Constructors
TCBase BaseTy | Base types are (nullary) type constructors. |
TCCmd | Command types. |
TCDelay | Delayed computations. |
TCSum | Sum types. |
TCProd | Product types. |
TCFun | Function types. |
TCUser Var | User-defined type constructor. |
Instances
FromJSON TyCon Source # | |
Defined in Swarm.Language.Types | |
ToJSON TyCon Source # | |
Data TyCon Source # | |
Defined in Swarm.Language.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TyCon -> c TyCon # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TyCon # dataTypeOf :: TyCon -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c TyCon) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TyCon) # gmapT :: (forall b. Data b => b -> b) -> TyCon -> TyCon # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TyCon -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TyCon -> r # gmapQ :: (forall d. Data d => d -> u) -> TyCon -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> TyCon -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> TyCon -> m TyCon # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TyCon -> m TyCon # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TyCon -> m TyCon # | |
Generic TyCon Source # | |
Show TyCon Source # | |
Eq TyCon Source # | |
Ord TyCon Source # | |
PrettyPrec TyCon Source # | |
Defined in Swarm.Language.Pretty | |
type Rep TyCon Source # | |
Defined in Swarm.Language.Types type Rep TyCon = D1 ('MetaData "TyCon" "Swarm.Language.Types" "swarm-0.6.0.0-ERx1HMcRMba59aI2b6aNrS-swarm-lang" 'False) ((C1 ('MetaCons "TCBase" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 BaseTy)) :+: (C1 ('MetaCons "TCCmd" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TCDelay" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "TCSum" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TCProd" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "TCFun" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TCUser" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Var))))) |
The arity of a type, i.e. the number of type parameters it expects.
Instances
FromJSON Arity Source # | |
Defined in Swarm.Language.Types | |
ToJSON Arity Source # | |
Data Arity Source # | |
Defined in Swarm.Language.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Arity -> c Arity # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Arity # dataTypeOf :: Arity -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Arity) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Arity) # gmapT :: (forall b. Data b => b -> b) -> Arity -> Arity # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Arity -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Arity -> r # gmapQ :: (forall d. Data d => d -> u) -> Arity -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Arity -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Arity -> m Arity # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Arity -> m Arity # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Arity -> m Arity # | |
Generic Arity Source # | |
Show Arity Source # | |
Eq Arity Source # | |
Ord Arity Source # | |
PrettyPrec Arity Source # | |
Defined in Swarm.Language.Pretty | |
type Rep Arity Source # | |
Defined in Swarm.Language.Types |
tcArity :: TDCtx -> TyCon -> Maybe Arity Source #
The arity, i.e. number of type arguments, of each type constructor. Eventually, if we generalize to higher-kinded types, we'll need to upgrade this to return a full-fledged kind instead of just an arity.
Type structure functor
A "structure functor" encoding the shape of type expressions. Actual types are then represented by taking a fixed point of this functor. We represent types in this way, via a "two-level type", so that we can easily use generic recursion schemes to implement things like substitution.
Constructors
TyConF TyCon [t] | A type constructor applied to some type arguments. For now, all type constructor applications are required to be fully saturated (higher kinds are not supported), so we just directly store a list of all arguments (as opposed to iterating binary application). |
TyVarF Var | A type variable. |
TyRcdF (Map Var t) | Record type. |
TyRecVarF Nat | A recursive type variable bound by an enclosing Rec, represented by a de Bruijn index. |
TyRecF Var t | Recursive type. The variable is just a suggestion for a name to use when pretty-printing; the actual bound variables are represented via de Bruijn indices. |
Instances
Recursive types
Peano naturals, for use as de Bruijn indices in recursive types.
Instances
FromJSON Nat Source # | |
Defined in Swarm.Language.Types | |
ToJSON Nat Source # | |
Data Nat Source # | |
Defined in Swarm.Language.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Nat -> c Nat # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Nat # dataTypeOf :: Nat -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Nat) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Nat) # gmapT :: (forall b. Data b => b -> b) -> Nat -> Nat # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Nat -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Nat -> r # gmapQ :: (forall d. Data d => d -> u) -> Nat -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Nat -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Nat -> m Nat # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Nat -> m Nat # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Nat -> m Nat # | |
Generic Nat Source # | |
Show Nat Source # | |
Eq Nat Source # | |
Ord Nat Source # | |
type Rep Nat Source # | |
Defined in Swarm.Language.Types type Rep Nat = D1 ('MetaData "Nat" "Swarm.Language.Types" "swarm-0.6.0.0-ERx1HMcRMba59aI2b6aNrS-swarm-lang" 'False) (C1 ('MetaCons "NZ" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NS" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Nat))) |
unfoldRec :: SubstRec t => Var -> t -> t Source #
unfoldRec x t
unfolds the recursive type rec x. t
one step,
to t [(rec x. t) / x]
.
class SubstRec t where Source #
Class of type-like things where we can substitute for a bound de Bruijn variable.
Type
UType
Instances
Data IntVar Source # | |
Defined in Swarm.Language.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IntVar -> c IntVar # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c IntVar # toConstr :: IntVar -> Constr # dataTypeOf :: IntVar -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c IntVar) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntVar) # gmapT :: (forall b. Data b => b -> b) -> IntVar -> IntVar # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntVar -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntVar -> r # gmapQ :: (forall d. Data d => d -> u) -> IntVar -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> IntVar -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> IntVar -> m IntVar # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IntVar -> m IntVar # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IntVar -> m IntVar # | |
IsString UType Source # | |
Defined in Swarm.Language.Types Methods fromString :: String -> UType # | |
Show IntVar Source # | |
Eq IntVar Source # | |
Ord IntVar Source # | |
PrettyPrec IntVar Source # | |
Defined in Swarm.Language.Pretty | |
PrettyPrec UPolytype Source # | |
Defined in Swarm.Language.Pretty | |
Substitutes IntVar UType UType Source # | We can perform substitution on terms built up as the free monad
over a structure functor |
Utilities
mkVarName :: Text -> IntVar -> Var Source #
A quick-and-dirty method for turning an IntVar
(used internally
as a unification variable) into a unique variable name, by
appending a number to the given name.
Polytypes
A Poly t
is a universally quantified t
. The variables in the
list are bound inside the t
. For example, the type forall
a. a -> a
would be represented as Forall ["a"] (TyFun "a" "a")
.
Instances
FromJSON TSyntax Source # | |
Defined in Swarm.Language.JSON | |
ToJSON TSyntax Source # | |
Foldable Poly Source # | |
Defined in Swarm.Language.Types Methods fold :: Monoid m => Poly m -> m # foldMap :: Monoid m => (a -> m) -> Poly a -> m # foldMap' :: Monoid m => (a -> m) -> Poly a -> m # foldr :: (a -> b -> b) -> b -> Poly a -> b # foldr' :: (a -> b -> b) -> b -> Poly a -> b # foldl :: (b -> a -> b) -> b -> Poly a -> b # foldl' :: (b -> a -> b) -> b -> Poly a -> b # foldr1 :: (a -> a -> a) -> Poly a -> a # foldl1 :: (a -> a -> a) -> Poly a -> a # elem :: Eq a => a -> Poly a -> Bool # maximum :: Ord a => Poly a -> a # | |
Traversable Poly Source # | |
Functor Poly Source # | |
PrettyPrec Polytype Source # | |
Defined in Swarm.Language.Pretty | |
PrettyPrec UPolytype Source # | |
Defined in Swarm.Language.Pretty | |
FromJSON t => FromJSON (Poly t) Source # | |
Defined in Swarm.Language.Types | |
ToJSON t => ToJSON (Poly t) Source # | |
Data t => Data (Poly t) Source # | |
Defined in Swarm.Language.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Poly t -> c (Poly t) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Poly t) # toConstr :: Poly t -> Constr # dataTypeOf :: Poly t -> DataType # dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Poly t)) # dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Poly t)) # gmapT :: (forall b. Data b => b -> b) -> Poly t -> Poly t # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Poly t -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Poly t -> r # gmapQ :: (forall d. Data d => d -> u) -> Poly t -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Poly t -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Poly t -> m (Poly t) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Poly t -> m (Poly t) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Poly t -> m (Poly t) # | |
Generic (Poly t) Source # | |
Show t => Show (Poly t) Source # | |
Eq t => Eq (Poly t) Source # | |
type Rep (Poly t) Source # | |
Defined in Swarm.Language.Types type Rep (Poly t) = D1 ('MetaData "Poly" "Swarm.Language.Types" "swarm-0.6.0.0-ERx1HMcRMba59aI2b6aNrS-swarm-lang" 'False) (C1 ('MetaCons "Forall" 'PrefixI 'True) (S1 ('MetaSel ('Just "ptVars") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [Var]) :*: S1 ('MetaSel ('Just "ptBody") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 t))) |
Contexts
type TCtx = Ctx Polytype Source #
A TCtx
is a mapping from variables to polytypes. We generally
get one of these at the end of the type inference process.
type UCtx = Ctx UPolytype Source #
A UCtx
is a mapping from variables to polytypes with
unification variables. We generally have one of these while we
are in the midst of the type inference process.
User type definitions
Constructors
TydefInfo | |
Fields
|
Instances
FromJSON TydefInfo Source # | |
Defined in Swarm.Language.Types | |
ToJSON TydefInfo Source # | |
Data TydefInfo Source # | |
Defined in Swarm.Language.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TydefInfo -> c TydefInfo # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TydefInfo # toConstr :: TydefInfo -> Constr # dataTypeOf :: TydefInfo -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c TydefInfo) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TydefInfo) # gmapT :: (forall b. Data b => b -> b) -> TydefInfo -> TydefInfo # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TydefInfo -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TydefInfo -> r # gmapQ :: (forall d. Data d => d -> u) -> TydefInfo -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> TydefInfo -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> TydefInfo -> m TydefInfo # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TydefInfo -> m TydefInfo # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TydefInfo -> m TydefInfo # | |
Generic TydefInfo Source # | |
Show TydefInfo Source # | |
Eq TydefInfo Source # | |
type Rep TydefInfo Source # | |
Defined in Swarm.Language.Types type Rep TydefInfo = D1 ('MetaData "TydefInfo" "Swarm.Language.Types" "swarm-0.6.0.0-ERx1HMcRMba59aI2b6aNrS-swarm-lang" 'False) (C1 ('MetaCons "TydefInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "_tydefType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Polytype) :*: S1 ('MetaSel ('Just "_tydefArity") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Arity))) |
substTydef :: forall t. Typical t => TydefInfo -> [t] -> t Source #
Given the definition of a type alias, substitute the given arguments into its body and return the resulting type.
expandTydef :: (Has (Reader TDCtx) sig m, Typical t) => Var -> [t] -> m t Source #
Expand an application "T ty1 ty2 ... tyn" by looking up the definition of T and substituting ty1 .. tyn for its arguments.
Note that this has already been kind-checked so we know the number of arguments must match up; we don't worry about what happens if the lists have different lengths since in theory that can never happen.
elimTydef :: forall t. Typical t => Var -> TydefInfo -> t -> t Source #
Replace a type alias with its definition everywhere it occurs inside a type. Typically this is done when reporting the type of a term containing a local tydef: since the tydef is local we can't use it in the reported type.
type TDCtx = Ctx TydefInfo Source #
A TDCtx
is a mapping from user-defined type constructor names
to their definitions and arities/kinds.
WHNF
whnfType :: TDCtx -> Type -> Type Source #
Reduce a type to weak head normal form, i.e. keep unfold type
aliases and recursive types just until the top-level constructor
of the type is neither rec
nor an application of a type alias.
The WithU
class
In several cases we have two versions of something: a "normal"
version, and a U
version with unification variables in it
(e.g. Type
vs UType
, Polytype
vs UPolytype
, TCtx
vs
UCtx
). This class abstracts over the process of converting back
and forth between them.
In particular,
represents the fact that the type WithU
tt
also has a U
counterpart, with a way to convert back and forth.
Note, however, that converting back may be "unsafe" in the sense
that it requires an extra burden of proof to guarantee that it is
used only on inputs that are safe.
Methods
Convert from t
to its associated "U
-version". This
direction is always safe (we simply have no unification
variables even though the type allows it).
fromU :: U t -> Maybe t Source #
Convert from the associated "U
-version" back to t
.
Generally, this direction requires somehow knowing that there
are no longer any unification variables in the value being
converted.