License | BSD-3-Clause |
---|---|
Safe Haskell | None |
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 :: Typical t => t -> 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 TyType :: 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 :: TDVar -> [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 UTyVar' :: Var -> 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 UTyType :: 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 :: TDVar -> [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
- hasAnyUVars :: UType -> Bool
- isTopLevelConstructor :: UType -> Maybe (TypeF ())
- class UnchainableFun t where
- unchainFun :: t -> NonEmpty t
- data ImplicitQuantification
- data Poly (q :: ImplicitQuantification) t
- mkPoly :: [Var] -> t -> Poly 'Unquantified t
- mkQPoly :: Typical t => t -> Poly 'Quantified t
- mkTrivPoly :: forall t (q :: ImplicitQuantification). t -> Poly q t
- unPoly :: Poly 'Quantified t -> ([Var], t)
- ptVars :: Poly 'Quantified t -> [Var]
- ptBody :: Poly q t -> t
- type Polytype = Poly 'Quantified Type
- type RawPolytype = Poly 'Unquantified Type
- pattern PolyUnit :: Polytype
- type UPolytype = Poly 'Quantified UType
- quantify :: forall (sig :: (Type -> Type) -> Type -> Type) m ty. (Has (Reader TVCtx) sig m, Typical ty) => Poly 'Unquantified ty -> m (Poly 'Quantified ty)
- absQuantify :: Typical t => Poly 'Unquantified t -> Poly 'Quantified t
- forgetQ :: Poly 'Quantified t -> Poly 'Unquantified t
- type TCtx = Ctx Var Polytype
- type UCtx = Ctx Var UPolytype
- type TVCtx = Ctx Var UType
- data TydefInfo = TydefInfo {}
- tydefType :: Lens' TydefInfo Polytype
- tydefArity :: Lens' TydefInfo Arity
- substTydef :: Typical t => TydefInfo -> [t] -> t
- newtype ExpandTydefErr = UnexpandedUserType {}
- expandTydef :: forall (sig :: (Type -> Type) -> Type -> Type) m t. (Has (Reader TDCtx) sig m, Has (Throw ExpandTydefErr) sig m, Typical t) => TDVar -> [t] -> m t
- expandTydefs :: forall (sig :: (Type -> Type) -> Type -> Type) m t. (Has (Reader TDCtx) sig m, Has (Throw ExpandTydefErr) sig m, Typical t, Plated t) => t -> m t
- elimTydef :: Typical t => TDVar -> TydefInfo -> t -> t
- data TDCtx
- emptyTDCtx :: TDCtx
- lookupTD :: TDVar -> TDCtx -> Maybe TydefInfo
- lookupTDR :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (Reader TDCtx) sig m => TDVar -> m (Maybe TydefInfo)
- addBindingTD :: Text -> TydefInfo -> TDCtx -> TDCtx
- withBindingTD :: forall (sig :: (Type -> Type) -> Type -> Type) m a. Has (Reader TDCtx) sig m => Text -> TydefInfo -> m a -> m a
- resolveUserTy :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (Reader TDCtx) sig m => TDVar -> m TDVar
- 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 |
BType | The type of types |
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 # | |||||
Defined in Swarm.Language.Types Associated Types
| |||||
Show BaseTy Source # | |||||
Eq BaseTy Source # | |||||
Ord BaseTy Source # | |||||
Hashable BaseTy Source # | |||||
Defined in Swarm.Language.Types | |||||
PrettyPrec BaseTy Source # | |||||
Defined in Swarm.Language.Types Methods prettyPrec :: Int -> BaseTy -> Doc ann | |||||
type Rep BaseTy Source # | |||||
Defined in Swarm.Language.Types type Rep BaseTy = D1 ('MetaData "BaseTy" "Swarm.Language.Types" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-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) :+: C1 ('MetaCons "BType" '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 TDVar | 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 # | |||||
Defined in Swarm.Language.Types Associated Types
| |||||
Show TyCon Source # | |||||
Eq TyCon Source # | |||||
Ord TyCon Source # | |||||
Hashable TyCon Source # | |||||
Defined in Swarm.Language.Types | |||||
PrettyPrec TyCon Source # | |||||
Defined in Swarm.Language.Types Methods prettyPrec :: Int -> TyCon -> Doc ann | |||||
type Rep TyCon Source # | |||||
Defined in Swarm.Language.Types type Rep TyCon = D1 ('MetaData "TyCon" "Swarm.Language.Types" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-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 TDVar))))) |
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 # | |||||
Defined in Swarm.Language.Types Associated Types
| |||||
Show Arity Source # | |||||
Eq Arity Source # | |||||
Ord Arity Source # | |||||
Hashable Arity Source # | |||||
Defined in Swarm.Language.Types | |||||
PrettyPrec Arity Source # | |||||
Defined in Swarm.Language.Types Methods prettyPrec :: Int -> Arity -> Doc ann | |||||
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.
For now, we just use Text
to represent variables. In theory,
at some point in the future we might want to represent them in some
fancier way.
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 Var | A type variable. The first Var represents the original name, and should be ignored except for use in e.g. error messages. The second Var is the real name of the variable; it may be the same as the first, or it may be different e.g. if it is a freshly generated skolem 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 # | |||||
Defined in Swarm.Language.Types Associated Types
| |||||
Show Nat Source # | |||||
Eq Nat Source # | |||||
Ord Nat Source # | |||||
Hashable Nat Source # | |||||
Defined in Swarm.Language.Types | |||||
type Rep Nat Source # | |||||
Defined in Swarm.Language.Types type Rep Nat = D1 ('MetaData "Nat" "Swarm.Language.Types" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-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 # | |||||
Generic IntVar Source # | |||||
Defined in Swarm.Language.Types Associated Types
| |||||
Show IntVar Source # | |||||
Eq IntVar Source # | |||||
Ord IntVar Source # | |||||
Hashable IntVar Source # | |||||
Defined in Swarm.Language.Types | |||||
PrettyPrec IntVar Source # | |||||
Defined in Swarm.Language.Types Methods prettyPrec :: Int -> IntVar -> Doc ann | |||||
Substitutes IntVar UType UType Source # | We can perform substitution on terms built up as the free monad
over a structure functor | ||||
PrettyPrec (Poly q UType) Source # | |||||
Defined in Swarm.Language.Types Methods prettyPrec :: Int -> Poly q UType -> Doc ann | |||||
type Rep IntVar Source # | |||||
Defined in Swarm.Language.Types |
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.
hasAnyUVars :: UType -> Bool Source #
Check whether a type contains any unification variables at all.
isTopLevelConstructor :: UType -> Maybe (TypeF ()) Source #
Check whether a type consists of a top-level type constructor immediately applied to unification variables.
class UnchainableFun t where Source #
Split a function type chain, so that we can pretty print the type parameters aligned on each line when they don't fit.
Methods
unchainFun :: t -> NonEmpty t Source #
Instances
UnchainableFun Type Source # | |
Defined in Swarm.Language.Types | |
UnchainableFun (Free TypeF ty) Source # | |
Defined in Swarm.Language.Types |
Polytypes
data ImplicitQuantification Source #
Constructors
Unquantified | |
Quantified |
Instances
Read ImplicitQuantification Source # | |
Defined in Swarm.Language.Types | |
Show ImplicitQuantification Source # | |
Defined in Swarm.Language.Types Methods showsPrec :: Int -> ImplicitQuantification -> ShowS # show :: ImplicitQuantification -> String # showList :: [ImplicitQuantification] -> ShowS # | |
Eq ImplicitQuantification Source # | |
Defined in Swarm.Language.Types Methods (==) :: ImplicitQuantification -> ImplicitQuantification -> Bool # (/=) :: ImplicitQuantification -> ImplicitQuantification -> Bool # | |
Ord ImplicitQuantification Source # | |
Defined in Swarm.Language.Types Methods compare :: ImplicitQuantification -> ImplicitQuantification -> Ordering # (<) :: ImplicitQuantification -> ImplicitQuantification -> Bool # (<=) :: ImplicitQuantification -> ImplicitQuantification -> Bool # (>) :: ImplicitQuantification -> ImplicitQuantification -> Bool # (>=) :: ImplicitQuantification -> ImplicitQuantification -> Bool # max :: ImplicitQuantification -> ImplicitQuantification -> ImplicitQuantification # min :: ImplicitQuantification -> ImplicitQuantification -> ImplicitQuantification # |
data Poly (q :: ImplicitQuantification) t Source #
A Poly q 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")
.
The type index q
is a phantom type index indicating whether the
type has been implicitly quantified. Immediately after a
polytype is parsed it is Unquantified
and unsafe to use. For
example, the type a -> a
would parse literally as Forall []
(TyFun "a" "a") :: Poly Unquantified Type
, where the type
variable a
is not in the list of bound variables. Later, after
running through quantify
, it would become a Poly Quantified
Type
, either Forall ["a"] (TyFun "a" "a")
if the type variable
is implicitly quantified, or unchanged if the type variable a
was already in scope.
The Poly
constructor intentionally unexported, so that the
only way to create a Poly Quantified
is through the quantify
function.
Instances
FromJSON TSyntax Source # | |||||
Defined in Swarm.Language.JSON | |||||
ToJSON TSyntax Source # | |||||
Foldable (Poly q) Source # | |||||
Defined in Swarm.Language.Types Methods fold :: Monoid m => Poly q m -> m # foldMap :: Monoid m => (a -> m) -> Poly q a -> m # foldMap' :: Monoid m => (a -> m) -> Poly q a -> m # foldr :: (a -> b -> b) -> b -> Poly q a -> b # foldr' :: (a -> b -> b) -> b -> Poly q a -> b # foldl :: (b -> a -> b) -> b -> Poly q a -> b # foldl' :: (b -> a -> b) -> b -> Poly q a -> b # foldr1 :: (a -> a -> a) -> Poly q a -> a # foldl1 :: (a -> a -> a) -> Poly q a -> a # elem :: Eq a => a -> Poly q a -> Bool # maximum :: Ord a => Poly q a -> a # minimum :: Ord a => Poly q a -> a # | |||||
Traversable (Poly q) Source # | |||||
Functor (Poly q) Source # | |||||
FromJSON t => FromJSON (Poly q t) Source # | |||||
Defined in Swarm.Language.Types | |||||
ToJSON t => ToJSON (Poly q t) Source # | |||||
(Typeable q, Data t) => Data (Poly q 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 q t -> c (Poly q t) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Poly q t) # toConstr :: Poly q t -> Constr # dataTypeOf :: Poly q t -> DataType # dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Poly q t)) # dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Poly q t)) # gmapT :: (forall b. Data b => b -> b) -> Poly q t -> Poly q t # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Poly q t -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Poly q t -> r # gmapQ :: (forall d. Data d => d -> u) -> Poly q t -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Poly q t -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Poly q t -> m (Poly q t) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Poly q t -> m (Poly q t) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Poly q t -> m (Poly q t) # | |||||
Generic (Poly q t) Source # | |||||
Defined in Swarm.Language.Types Associated Types
| |||||
Show t => Show (Poly q t) Source # | |||||
Eq t => Eq (Poly q t) Source # | |||||
Hashable t => Hashable (Poly q t) Source # | |||||
Defined in Swarm.Language.Types | |||||
PrettyPrec (Poly q Type) Source # | |||||
Defined in Swarm.Language.Types Methods prettyPrec :: Int -> Poly q Type -> Doc ann | |||||
PrettyPrec (Poly q UType) Source # | |||||
Defined in Swarm.Language.Types Methods prettyPrec :: Int -> Poly q UType -> Doc ann | |||||
type Rep (Poly q t) Source # | |||||
Defined in Swarm.Language.Types type Rep (Poly q t) = D1 ('MetaData "Poly" "Swarm.Language.Types" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-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))) |
mkQPoly :: Typical t => t -> Poly 'Quantified t Source #
Create a polytype while performing implicit quantification.
mkTrivPoly :: forall t (q :: ImplicitQuantification). t -> Poly q t Source #
Create a trivial "polytype" with no bound variables. This is somewhat unsafe --- only use this if you are sure that the polytype you want has no type variables.
unPoly :: Poly 'Quantified t -> ([Var], t) Source #
Project out the variables and body of a Poly
value. It's only
possible to project from a 'Poly Quantified' since the list of
variables might be meaningless for a type that has not had
implicit quantification applied.
ptVars :: Poly 'Quantified t -> [Var] Source #
Project out the variables of a 'Poly Quantified' value.
type Polytype = Poly 'Quantified Type Source #
A regular polytype (without unification variables). A Polytype
(as opposed to a RawPolytype
) is guaranteed to have implicit
quantification properly applied, so that all type variables bound
by the forall are explicitly listed.
type RawPolytype = Poly 'Unquantified Type Source #
A raw polytype (without unification variables), which corresponds exactly to the way a polytype was written in source code. In particular there may be type variables which are used in the type but not listed explicitly, which are to be implicitly quantified.
quantify :: forall (sig :: (Type -> Type) -> Type -> Type) m ty. (Has (Reader TVCtx) sig m, Typical ty) => Poly 'Unquantified ty -> m (Poly 'Quantified ty) Source #
Implicitly quantify any otherwise unbound type variables.
absQuantify :: Typical t => Poly 'Unquantified t -> Poly 'Quantified t Source #
Absolute implicit quantification, i.e. assume there are no type variables in scope.
forgetQ :: Poly 'Quantified t -> Poly 'Unquantified t Source #
Forget that a polytype has been properly quantified.
Contexts
type TCtx = Ctx Var 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 Var 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.
type TVCtx = Ctx Var UType Source #
A TVCtx
tracks which type variables are in scope, and what
skolem variables were assigned to them.
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 # | |||||
Defined in Swarm.Language.Types Associated Types
| |||||
Show TydefInfo Source # | |||||
Eq TydefInfo Source # | |||||
Hashable TydefInfo Source # | |||||
Defined in Swarm.Language.Types | |||||
type Rep TydefInfo Source # | |||||
Defined in Swarm.Language.Types type Rep TydefInfo = D1 ('MetaData "TydefInfo" "Swarm.Language.Types" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-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 :: 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.
newtype ExpandTydefErr Source #
Constructors
UnexpandedUserType | |
Fields |
Instances
Show ExpandTydefErr Source # | |
Defined in Swarm.Language.Types Methods showsPrec :: Int -> ExpandTydefErr -> ShowS # show :: ExpandTydefErr -> String # showList :: [ExpandTydefErr] -> ShowS # | |
Eq ExpandTydefErr Source # | |
Defined in Swarm.Language.Types Methods (==) :: ExpandTydefErr -> ExpandTydefErr -> Bool # (/=) :: ExpandTydefErr -> ExpandTydefErr -> Bool # |
expandTydef :: forall (sig :: (Type -> Type) -> Type -> Type) m t. (Has (Reader TDCtx) sig m, Has (Throw ExpandTydefErr) sig m, Typical t) => TDVar -> [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, and user types must be defined; we don't worry about what happens if the lists have different lengths since in theory that can never happen. However, if T does not exist, we throw an error containing its name.
expandTydefs :: forall (sig :: (Type -> Type) -> Type -> Type) m t. (Has (Reader TDCtx) sig m, Has (Throw ExpandTydefErr) sig m, Typical t, Plated t) => t -> m t Source #
Expand *all* applications of user-defined type constructors everywhere in a type.
elimTydef :: Typical t => TDVar -> 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.
A TDCtx
is a mapping from user-defined type constructor names
to their definitions and arities/kinds. It also stores the
latest version of each name (for any names with more than one
version), so we can tell when a type definition has been
shadowed.
Instances
ToJSON TDCtx Source # | |||||
Generic TDCtx Source # | |||||
Defined in Swarm.Language.Types Associated Types
| |||||
Show TDCtx Source # | |||||
Eq TDCtx Source # | |||||
Hashable TDCtx Source # | |||||
Defined in Swarm.Language.Types | |||||
type Rep TDCtx Source # | |||||
Defined in Swarm.Language.Types type Rep TDCtx = D1 ('MetaData "TDCtx" "Swarm.Language.Types" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-swarm-lang" 'False) (C1 ('MetaCons "TDCtx" 'PrefixI 'True) (S1 ('MetaSel ('Just "getTDCtx") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Ctx TDVar TydefInfo)) :*: S1 ('MetaSel ('Just "getTDVersions") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (MonoidMap Text (Sum Int))))) |
emptyTDCtx :: TDCtx Source #
The empty type definition context.
lookupTD :: TDVar -> TDCtx -> Maybe TydefInfo Source #
Look up a variable in the type definition context.
lookupTDR :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (Reader TDCtx) sig m => TDVar -> m (Maybe TydefInfo) Source #
Look up a variable in an ambient type definition context.
addBindingTD :: Text -> TydefInfo -> TDCtx -> TDCtx Source #
Add a binding of a variable name to a type definition, giving it an appropriate version number if it shadows other variables with the same name.
withBindingTD :: forall (sig :: (Type -> Type) -> Type -> Type) m a. Has (Reader TDCtx) sig m => Text -> TydefInfo -> m a -> m a Source #
Locally extend the ambient type definition context with an
additional binding, via addBindingTD
.
resolveUserTy :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (Reader TDCtx) sig m => TDVar -> m TDVar Source #
Given a parsed variable representing a user-defined type, figure out which version is currently in scope and set the version number of the variable appropriately.
WHNF
whnfType :: TDCtx -> Type -> Type Source #
Reduce a type to weak head normal form, i.e. keep unfolding type
aliases and recursive types just until the top-level constructor
of the type is neither rec
nor an application of a defined 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.