swarm-0.7.0.0: 2D resource gathering game with programmable robots
LicenseBSD-3-Clause
Safe HaskellNone
LanguageHaskell2010

Swarm.Language.Types

Description

Types for the Swarm programming language and related utilities.

Synopsis

Basic definitions

Base types and type constructors

data BaseTy Source #

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

Instances details
FromJSON BaseTy Source # 
Instance details

Defined in Swarm.Language.Types

ToJSON BaseTy Source # 
Instance details

Defined in Swarm.Language.Types

Data BaseTy Source # 
Instance details

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 # 
Instance details

Defined in Swarm.Language.Types

Enum BaseTy Source # 
Instance details

Defined in Swarm.Language.Types

Generic BaseTy Source # 
Instance details

Defined in Swarm.Language.Types

Associated Types

type Rep BaseTy 
Instance details

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)))))

Methods

from :: BaseTy -> Rep BaseTy x #

to :: Rep BaseTy x -> BaseTy #

Show BaseTy Source # 
Instance details

Defined in Swarm.Language.Types

Eq BaseTy Source # 
Instance details

Defined in Swarm.Language.Types

Methods

(==) :: BaseTy -> BaseTy -> Bool #

(/=) :: BaseTy -> BaseTy -> Bool #

Ord BaseTy Source # 
Instance details

Defined in Swarm.Language.Types

Hashable BaseTy Source # 
Instance details

Defined in Swarm.Language.Types

Methods

hashWithSalt :: Int -> BaseTy -> Int #

hash :: BaseTy -> Int #

PrettyPrec BaseTy Source # 
Instance details

Defined in Swarm.Language.Types

Methods

prettyPrec :: Int -> BaseTy -> Doc ann

type Rep BaseTy Source # 
Instance details

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)))))

data TyCon 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

Instances details
FromJSON TyCon Source # 
Instance details

Defined in Swarm.Language.Types

ToJSON TyCon Source # 
Instance details

Defined in Swarm.Language.Types

Data TyCon Source # 
Instance details

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 #

toConstr :: TyCon -> Constr #

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 # 
Instance details

Defined in Swarm.Language.Types

Associated Types

type Rep TyCon 
Instance details

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)))))

Methods

from :: TyCon -> Rep TyCon x #

to :: Rep TyCon x -> TyCon #

Show TyCon Source # 
Instance details

Defined in Swarm.Language.Types

Methods

showsPrec :: Int -> TyCon -> ShowS #

show :: TyCon -> String #

showList :: [TyCon] -> ShowS #

Eq TyCon Source # 
Instance details

Defined in Swarm.Language.Types

Methods

(==) :: TyCon -> TyCon -> Bool #

(/=) :: TyCon -> TyCon -> Bool #

Ord TyCon Source # 
Instance details

Defined in Swarm.Language.Types

Methods

compare :: TyCon -> TyCon -> Ordering #

(<) :: TyCon -> TyCon -> Bool #

(<=) :: TyCon -> TyCon -> Bool #

(>) :: TyCon -> TyCon -> Bool #

(>=) :: TyCon -> TyCon -> Bool #

max :: TyCon -> TyCon -> TyCon #

min :: TyCon -> TyCon -> TyCon #

Hashable TyCon Source # 
Instance details

Defined in Swarm.Language.Types

Methods

hashWithSalt :: Int -> TyCon -> Int #

hash :: TyCon -> Int #

PrettyPrec TyCon Source # 
Instance details

Defined in Swarm.Language.Types

Methods

prettyPrec :: Int -> TyCon -> Doc ann

type Rep TyCon Source # 
Instance details

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)))))

newtype Arity Source #

The arity of a type, i.e. the number of type parameters it expects.

Constructors

Arity 

Fields

Instances

Instances details
FromJSON Arity Source # 
Instance details

Defined in Swarm.Language.Types

ToJSON Arity Source # 
Instance details

Defined in Swarm.Language.Types

Data Arity Source # 
Instance details

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 #

toConstr :: Arity -> Constr #

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 # 
Instance details

Defined in Swarm.Language.Types

Associated Types

type Rep Arity 
Instance details

Defined in Swarm.Language.Types

type Rep Arity = D1 ('MetaData "Arity" "Swarm.Language.Types" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-swarm-lang" 'True) (C1 ('MetaCons "Arity" 'PrefixI 'True) (S1 ('MetaSel ('Just "getArity") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

Methods

from :: Arity -> Rep Arity x #

to :: Rep Arity x -> Arity #

Show Arity Source # 
Instance details

Defined in Swarm.Language.Types

Methods

showsPrec :: Int -> Arity -> ShowS #

show :: Arity -> String #

showList :: [Arity] -> ShowS #

Eq Arity Source # 
Instance details

Defined in Swarm.Language.Types

Methods

(==) :: Arity -> Arity -> Bool #

(/=) :: Arity -> Arity -> Bool #

Ord Arity Source # 
Instance details

Defined in Swarm.Language.Types

Methods

compare :: Arity -> Arity -> Ordering #

(<) :: Arity -> Arity -> Bool #

(<=) :: Arity -> Arity -> Bool #

(>) :: Arity -> Arity -> Bool #

(>=) :: Arity -> Arity -> Bool #

max :: Arity -> Arity -> Arity #

min :: Arity -> Arity -> Arity #

Hashable Arity Source # 
Instance details

Defined in Swarm.Language.Types

Methods

hashWithSalt :: Int -> Arity -> Int #

hash :: Arity -> Int #

PrettyPrec Arity Source # 
Instance details

Defined in Swarm.Language.Types

Methods

prettyPrec :: Int -> Arity -> Doc ann

type Rep Arity Source # 
Instance details

Defined in Swarm.Language.Types

type Rep Arity = D1 ('MetaData "Arity" "Swarm.Language.Types" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-swarm-lang" 'True) (C1 ('MetaCons "Arity" 'PrefixI 'True) (S1 ('MetaSel ('Just "getArity") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

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 Var = Text Source #

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

data TypeF t Source #

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

Instances details
FromJSON TSyntax Source # 
Instance details

Defined in Swarm.Language.JSON

FromJSON1 TypeF Source # 
Instance details

Defined in Swarm.Language.Types

Methods

liftParseJSON :: Maybe a -> (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (TypeF a) #

liftParseJSONList :: Maybe a -> (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [TypeF a] #

liftOmittedField :: Maybe a -> Maybe (TypeF a) #

ToJSON TSyntax Source # 
Instance details

Defined in Swarm.Language.JSON

ToJSON1 TypeF Source # 
Instance details

Defined in Swarm.Language.Types

Methods

liftToJSON :: (a -> Bool) -> (a -> Value) -> ([a] -> Value) -> TypeF a -> Value #

liftToJSONList :: (a -> Bool) -> (a -> Value) -> ([a] -> Value) -> [TypeF a] -> Value #

liftToEncoding :: (a -> Bool) -> (a -> Encoding) -> ([a] -> Encoding) -> TypeF a -> Encoding #

liftToEncodingList :: (a -> Bool) -> (a -> Encoding) -> ([a] -> Encoding) -> [TypeF a] -> Encoding #

liftOmitField :: (a -> Bool) -> TypeF a -> Bool #

Foldable TypeF Source # 
Instance details

Defined in Swarm.Language.Types

Methods

fold :: Monoid m => TypeF m -> m #

foldMap :: Monoid m => (a -> m) -> TypeF a -> m #

foldMap' :: Monoid m => (a -> m) -> TypeF a -> m #

foldr :: (a -> b -> b) -> b -> TypeF a -> b #

foldr' :: (a -> b -> b) -> b -> TypeF a -> b #

foldl :: (b -> a -> b) -> b -> TypeF a -> b #

foldl' :: (b -> a -> b) -> b -> TypeF a -> b #

foldr1 :: (a -> a -> a) -> TypeF a -> a #

foldl1 :: (a -> a -> a) -> TypeF a -> a #

toList :: TypeF a -> [a] #

null :: TypeF a -> Bool #

length :: TypeF a -> Int #

elem :: Eq a => a -> TypeF a -> Bool #

maximum :: Ord a => TypeF a -> a #

minimum :: Ord a => TypeF a -> a #

sum :: Num a => TypeF a -> a #

product :: Num a => TypeF a -> a #

Eq1 TypeF Source # 
Instance details

Defined in Swarm.Language.Types

Methods

liftEq :: (a -> b -> Bool) -> TypeF a -> TypeF b -> Bool #

Ord1 TypeF Source # 
Instance details

Defined in Swarm.Language.Types

Methods

liftCompare :: (a -> b -> Ordering) -> TypeF a -> TypeF b -> Ordering #

Show1 TypeF Source # 
Instance details

Defined in Swarm.Language.Types

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> TypeF a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [TypeF a] -> ShowS #

IsString Type Source #

For convenience, so we can write e.g. "a" instead of TyVar "a".

Instance details

Defined in Swarm.Language.Types

Methods

fromString :: String -> Type #

IsString UType Source # 
Instance details

Defined in Swarm.Language.Types

Methods

fromString :: String -> UType #

Traversable TypeF Source # 
Instance details

Defined in Swarm.Language.Types

Methods

traverse :: Applicative f => (a -> f b) -> TypeF a -> f (TypeF b) #

sequenceA :: Applicative f => TypeF (f a) -> f (TypeF a) #

mapM :: Monad m => (a -> m b) -> TypeF a -> m (TypeF b) #

sequence :: Monad m => TypeF (m a) -> m (TypeF a) #

Functor TypeF Source # 
Instance details

Defined in Swarm.Language.Types

Methods

fmap :: (a -> b) -> TypeF a -> TypeF b #

(<$) :: a -> TypeF b -> TypeF a #

Hashable1 TypeF Source # 
Instance details

Defined in Swarm.Language.Types

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> TypeF a -> Int #

Plated Type Source # 
Instance details

Defined in Swarm.Language.Types

SubstRec Type Source # 
Instance details

Defined in Swarm.Language.Types

Methods

substRec :: TypeF Type -> Type -> Nat -> Type Source #

UnchainableFun Type Source # 
Instance details

Defined in Swarm.Language.Types

WithU Type Source #

Type is an instance of WithU, with associated type UType.

Instance details

Defined in Swarm.Language.Types

Associated Types

type U Type 
Instance details

Defined in Swarm.Language.Types

type U Type = UType

Methods

toU :: Type -> U Type Source #

fromU :: U Type -> Maybe Type Source #

Generic1 TypeF Source # 
Instance details

Defined in Swarm.Language.Types

Methods

from1 :: TypeF a -> Rep1 TypeF a #

to1 :: Rep1 TypeF a -> TypeF a #

Substitutes IntVar UType UType Source #

We can perform substitution on terms built up as the free monad over a structure functor f.

Instance details

Defined in Swarm.Effect.Unify.Fast

Methods

subst :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (Throw UnificationError) sig m => Subst IntVar UType -> UType -> m UType Source #

Data t => Data (TypeF t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TypeF t -> c (TypeF t) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (TypeF t) #

toConstr :: TypeF t -> Constr #

dataTypeOf :: TypeF t -> DataType #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (TypeF t)) #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (TypeF t)) #

gmapT :: (forall b. Data b => b -> b) -> TypeF t -> TypeF t #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TypeF t -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TypeF t -> r #

gmapQ :: (forall d. Data d => d -> u) -> TypeF t -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> TypeF t -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> TypeF t -> m (TypeF t) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TypeF t -> m (TypeF t) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TypeF t -> m (TypeF t) #

Generic (TypeF t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

from :: TypeF t -> Rep (TypeF t) x #

to :: Rep (TypeF t) x -> TypeF t #

Show t => Show (TypeF t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

showsPrec :: Int -> TypeF t -> ShowS #

show :: TypeF t -> String #

showList :: [TypeF t] -> ShowS #

Eq t => Eq (TypeF t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

(==) :: TypeF t -> TypeF t -> Bool #

(/=) :: TypeF t -> TypeF t -> Bool #

Ord t => Ord (TypeF t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

compare :: TypeF t -> TypeF t -> Ordering #

(<) :: TypeF t -> TypeF t -> Bool #

(<=) :: TypeF t -> TypeF t -> Bool #

(>) :: TypeF t -> TypeF t -> Bool #

(>=) :: TypeF t -> TypeF t -> Bool #

max :: TypeF t -> TypeF t -> TypeF t #

min :: TypeF t -> TypeF t -> TypeF t #

Hashable t => Hashable (TypeF t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

hashWithSalt :: Int -> TypeF t -> Int #

hash :: TypeF t -> Int #

(UnchainableFun t, PrettyPrec t, SubstRec t) => PrettyPrec (TypeF t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

prettyPrec :: Int -> TypeF t -> Doc ann

SubstRec (Free TypeF v) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

substRec :: TypeF (Free TypeF v) -> Free TypeF v -> Nat -> Free TypeF v Source #

UnchainableFun (Free TypeF ty) Source # 
Instance details

Defined in Swarm.Language.Types

PrettyPrec (Poly q Type) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

prettyPrec :: Int -> Poly q Type -> Doc ann

PrettyPrec (Poly q UType) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

prettyPrec :: Int -> Poly q UType -> Doc ann

type U Type Source # 
Instance details

Defined in Swarm.Language.Types

type U Type = UType
type Rep1 TypeF Source # 
Instance details

Defined in Swarm.Language.Types

type Rep (TypeF t) Source # 
Instance details

Defined in Swarm.Language.Types

Recursive types

data Nat where Source #

Peano naturals, for use as de Bruijn indices in recursive types.

Constructors

NZ :: Nat 
NS :: Nat -> Nat 

Instances

Instances details
FromJSON Nat Source # 
Instance details

Defined in Swarm.Language.Types

ToJSON Nat Source # 
Instance details

Defined in Swarm.Language.Types

Data Nat Source # 
Instance details

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 #

toConstr :: Nat -> Constr #

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 # 
Instance details

Defined in Swarm.Language.Types

Associated Types

type Rep Nat 
Instance details

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)))

Methods

from :: Nat -> Rep Nat x #

to :: Rep Nat x -> Nat #

Show Nat Source # 
Instance details

Defined in Swarm.Language.Types

Methods

showsPrec :: Int -> Nat -> ShowS #

show :: Nat -> String #

showList :: [Nat] -> ShowS #

Eq Nat Source # 
Instance details

Defined in Swarm.Language.Types

Methods

(==) :: Nat -> Nat -> Bool #

(/=) :: Nat -> Nat -> Bool #

Ord Nat Source # 
Instance details

Defined in Swarm.Language.Types

Methods

compare :: Nat -> Nat -> Ordering #

(<) :: Nat -> Nat -> Bool #

(<=) :: Nat -> Nat -> Bool #

(>) :: Nat -> Nat -> Bool #

(>=) :: Nat -> Nat -> Bool #

max :: Nat -> Nat -> Nat #

min :: Nat -> Nat -> Nat #

Hashable Nat Source # 
Instance details

Defined in Swarm.Language.Types

Methods

hashWithSalt :: Int -> Nat -> Int #

hash :: Nat -> Int #

type Rep Nat Source # 
Instance details

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.

Methods

substRec :: TypeF t -> t -> Nat -> t Source #

substRec s t n substitutes s for the bound de Bruijn variable n everywhere in t.

Instances

Instances details
SubstRec Type Source # 
Instance details

Defined in Swarm.Language.Types

Methods

substRec :: TypeF Type -> Type -> Nat -> Type Source #

SubstRec (Free TypeF v) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

substRec :: TypeF (Free TypeF v) -> Free TypeF v -> Nat -> Free TypeF v Source #

Type

type Type = Fix TypeF Source #

Type is now defined as the fixed point of TypeF. It would be annoying to manually apply and match against Fix constructors everywhere, so we provide pattern synonyms that allow us to work with Type as if it were defined in a directly recursive way.

tyVars :: Typical t => t -> Set Var Source #

Get all the type variables (not unification variables) contained in a Type or UType.

pattern TyConApp :: TyCon -> [Type] -> Type Source #

pattern TyBase :: BaseTy -> Type Source #

pattern TyVar :: Var -> Type Source #

pattern TyVoid :: Type Source #

pattern TyUnit :: Type Source #

pattern TyInt :: Type Source #

pattern TyText :: Type Source #

pattern TyDir :: Type Source #

pattern TyBool :: Type Source #

pattern TyActor :: Type Source #

pattern TyKey :: Type Source #

pattern TyType :: Type Source #

pattern (:+:) :: Type -> Type -> Type infixr 5 Source #

pattern (:*:) :: Type -> Type -> Type infixr 6 Source #

pattern (:->:) :: Type -> Type -> Type infixr 1 Source #

pattern TyRcd :: Map Var Type -> Type Source #

pattern TyCmd :: Type -> Type Source #

pattern TyDelay :: Type -> Type Source #

pattern TyUser :: TDVar -> [Type] -> Type Source #

pattern TyRec :: Var -> Type -> Type Source #

UType

newtype IntVar Source #

Constructors

IntVar Int 

Instances

Instances details
Data IntVar Source # 
Instance details

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 # 
Instance details

Defined in Swarm.Language.Types

Methods

fromString :: String -> UType #

Generic IntVar Source # 
Instance details

Defined in Swarm.Language.Types

Associated Types

type Rep IntVar 
Instance details

Defined in Swarm.Language.Types

type Rep IntVar = D1 ('MetaData "IntVar" "Swarm.Language.Types" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-swarm-lang" 'True) (C1 ('MetaCons "IntVar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

Methods

from :: IntVar -> Rep IntVar x #

to :: Rep IntVar x -> IntVar #

Show IntVar Source # 
Instance details

Defined in Swarm.Language.Types

Eq IntVar Source # 
Instance details

Defined in Swarm.Language.Types

Methods

(==) :: IntVar -> IntVar -> Bool #

(/=) :: IntVar -> IntVar -> Bool #

Ord IntVar Source # 
Instance details

Defined in Swarm.Language.Types

Hashable IntVar Source # 
Instance details

Defined in Swarm.Language.Types

Methods

hashWithSalt :: Int -> IntVar -> Int #

hash :: IntVar -> Int #

PrettyPrec IntVar Source # 
Instance details

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 f.

Instance details

Defined in Swarm.Effect.Unify.Fast

Methods

subst :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (Throw UnificationError) sig m => Subst IntVar UType -> UType -> m UType Source #

PrettyPrec (Poly q UType) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

prettyPrec :: Int -> Poly q UType -> Doc ann

type Rep IntVar Source # 
Instance details

Defined in Swarm.Language.Types

type Rep IntVar = D1 ('MetaData "IntVar" "Swarm.Language.Types" "swarm-0.7.0.0-IuFfgHrMoE7JrptOBRVOwx-swarm-lang" 'True) (C1 ('MetaCons "IntVar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

type UType = Free TypeF IntVar Source #

UTypes are like Types, but also contain unification variables. UType is defined via Free, which is also a kind of fixed point (in fact, Free TypeF is the free monad over TypeF).

Just as with Type, we provide a bunch of pattern synonyms for working with UType as if it were defined directly.

pattern UTyConApp :: TyCon -> [UType] -> UType Source #

pattern UTyBase :: BaseTy -> UType Source #

pattern UTyVar :: Var -> UType Source #

pattern UTyVar' :: Var -> Var -> UType Source #

pattern UTyVoid :: UType Source #

pattern UTyUnit :: UType Source #

pattern UTyInt :: UType Source #

pattern UTyText :: UType Source #

pattern UTyDir :: UType Source #

pattern UTyBool :: UType Source #

pattern UTyActor :: UType Source #

pattern UTyKey :: UType Source #

pattern UTyType :: UType Source #

pattern UTySum :: UType -> UType -> UType Source #

pattern UTyProd :: UType -> UType -> UType Source #

pattern UTyFun :: UType -> UType -> UType Source #

pattern UTyRcd :: Map Var UType -> UType Source #

pattern UTyCmd :: UType -> UType Source #

pattern UTyDelay :: UType -> UType Source #

pattern UTyUser :: TDVar -> [UType] -> UType Source #

pattern UTyRec :: Var -> UType -> UType Source #

Utilities

ucata :: Functor t => (v -> a) -> (t a -> a) -> Free t v -> a Source #

A generic fold for things defined via Free (including, in particular, UType).

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.

fuvs :: UType -> Set IntVar Source #

Get all the free unification variables in a UType.

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

Instances details
UnchainableFun Type Source # 
Instance details

Defined in Swarm.Language.Types

UnchainableFun (Free TypeF ty) Source # 
Instance details

Defined in Swarm.Language.Types

Polytypes

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

Instances details
FromJSON TSyntax Source # 
Instance details

Defined in Swarm.Language.JSON

ToJSON TSyntax Source # 
Instance details

Defined in Swarm.Language.JSON

Foldable (Poly q) Source # 
Instance details

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 #

toList :: Poly q a -> [a] #

null :: Poly q a -> Bool #

length :: Poly q a -> Int #

elem :: Eq a => a -> Poly q a -> Bool #

maximum :: Ord a => Poly q a -> a #

minimum :: Ord a => Poly q a -> a #

sum :: Num a => Poly q a -> a #

product :: Num a => Poly q a -> a #

Traversable (Poly q) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

traverse :: Applicative f => (a -> f b) -> Poly q a -> f (Poly q b) #

sequenceA :: Applicative f => Poly q (f a) -> f (Poly q a) #

mapM :: Monad m => (a -> m b) -> Poly q a -> m (Poly q b) #

sequence :: Monad m => Poly q (m a) -> m (Poly q a) #

Functor (Poly q) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

fmap :: (a -> b) -> Poly q a -> Poly q b #

(<$) :: a -> Poly q b -> Poly q a #

FromJSON t => FromJSON (Poly q t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

parseJSON :: Value -> Parser (Poly q t) #

parseJSONList :: Value -> Parser [Poly q t] #

omittedField :: Maybe (Poly q t) #

ToJSON t => ToJSON (Poly q t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

toJSON :: Poly q t -> Value #

toEncoding :: Poly q t -> Encoding #

toJSONList :: [Poly q t] -> Value #

toEncodingList :: [Poly q t] -> Encoding #

omitField :: Poly q t -> Bool #

(Typeable q, Data t) => Data (Poly q t) Source # 
Instance details

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 # 
Instance details

Defined in Swarm.Language.Types

Associated Types

type Rep (Poly q t) 
Instance details

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)))

Methods

from :: Poly q t -> Rep (Poly q t) x #

to :: Rep (Poly q t) x -> Poly q t #

Show t => Show (Poly q t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

showsPrec :: Int -> Poly q t -> ShowS #

show :: Poly q t -> String #

showList :: [Poly q t] -> ShowS #

Eq t => Eq (Poly q t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

(==) :: Poly q t -> Poly q t -> Bool #

(/=) :: Poly q t -> Poly q t -> Bool #

Hashable t => Hashable (Poly q t) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

hashWithSalt :: Int -> Poly q t -> Int #

hash :: Poly q t -> Int #

PrettyPrec (Poly q Type) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

prettyPrec :: Int -> Poly q Type -> Doc ann

PrettyPrec (Poly q UType) Source # 
Instance details

Defined in Swarm.Language.Types

Methods

prettyPrec :: Int -> Poly q UType -> Doc ann

type Rep (Poly q t) Source # 
Instance details

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)))

mkPoly :: [Var] -> t -> Poly 'Unquantified t Source #

Create a raw, unquantified Poly value.

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.

ptBody :: Poly q t -> t Source #

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.

type UPolytype = Poly 'Quantified UType Source #

A polytype with unification variables.

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

data TydefInfo Source #

Constructors

TydefInfo 

Instances

Instances details
FromJSON TydefInfo Source # 
Instance details

Defined in Swarm.Language.Types

ToJSON TydefInfo Source # 
Instance details

Defined in Swarm.Language.Types

Data TydefInfo Source # 
Instance details

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 # 
Instance details

Defined in Swarm.Language.Types

Associated Types

type Rep TydefInfo 
Instance details

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)))
Show TydefInfo Source # 
Instance details

Defined in Swarm.Language.Types

Eq TydefInfo Source # 
Instance details

Defined in Swarm.Language.Types

Hashable TydefInfo Source # 
Instance details

Defined in Swarm.Language.Types

type Rep TydefInfo Source # 
Instance details

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

Instances details
Show ExpandTydefErr Source # 
Instance details

Defined in Swarm.Language.Types

Eq ExpandTydefErr Source # 
Instance details

Defined in Swarm.Language.Types

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.

data TDCtx Source #

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

Instances details
ToJSON TDCtx Source # 
Instance details

Defined in Swarm.Language.Types

Generic TDCtx Source # 
Instance details

Defined in Swarm.Language.Types

Associated Types

type Rep TDCtx 
Instance details

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)))))

Methods

from :: TDCtx -> Rep TDCtx x #

to :: Rep TDCtx x -> TDCtx #

Show TDCtx Source # 
Instance details

Defined in Swarm.Language.Types

Methods

showsPrec :: Int -> TDCtx -> ShowS #

show :: TDCtx -> String #

showList :: [TDCtx] -> ShowS #

Eq TDCtx Source # 
Instance details

Defined in Swarm.Language.Types

Methods

(==) :: TDCtx -> TDCtx -> Bool #

(/=) :: TDCtx -> TDCtx -> Bool #

Hashable TDCtx Source # 
Instance details

Defined in Swarm.Language.Types

Methods

hashWithSalt :: Int -> TDCtx -> Int #

hash :: TDCtx -> Int #

type Rep TDCtx Source # 
Instance details

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

class WithU t where Source #

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, WithU t represents the fact that the type t 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.

Associated Types

type U t Source #

The associated "U-version" of the type t.

Methods

toU :: t -> U t Source #

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.

Instances

Instances details
WithU Type Source #

Type is an instance of WithU, with associated type UType.

Instance details

Defined in Swarm.Language.Types

Associated Types

type U Type 
Instance details

Defined in Swarm.Language.Types

type U Type = UType

Methods

toU :: Type -> U Type Source #

fromU :: U Type -> Maybe Type Source #

(WithU t, Traversable f) => WithU (f t) Source #

A WithU instance can be lifted through any functor (including, in particular, Ctx and Poly).

Instance details

Defined in Swarm.Language.Types

Associated Types

type U (f t) 
Instance details

Defined in Swarm.Language.Types

type U (f t) = f (U t)

Methods

toU :: f t -> U (f t) Source #

fromU :: U (f t) -> Maybe (f t) Source #

Orphan instances

(Eq1 f, Hashable x, Hashable (f (Free f x))) => Hashable (Free f x) Source # 
Instance details

Methods

hashWithSalt :: Int -> Free f x -> Int #

hash :: Free f x -> Int #