| License | MIT |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
Language.Egison.Type.Types
Description
This module defines the type system for Egison.
Synopsis
- data Type
- data TypeScheme = Forall [TyVar] [Constraint] Type
- newtype TyVar = TyVar String
- data TensorShape
- data ShapeDimType
- data Constraint = Constraint {}
- data ClassInfo = ClassInfo {
- classSupers :: [String]
- classParam :: TyVar
- classMethods :: [(String, Type)]
- data InstanceInfo = InstanceInfo {
- instContext :: [Constraint]
- instClass :: String
- instType :: Type
- instMethods :: [(String, ())]
- freshTyVar :: String -> Int -> TyVar
- freeTyVars :: Type -> Set TyVar
- isTensorType :: Type -> Bool
- isScalarType :: Type -> Bool
- typeToName :: Type -> String
- typeConstructorName :: Type -> String
- sanitizeMethodName :: String -> String
- typeExprToType :: TypeExpr -> Type
- normalizeInductiveTypes :: Type -> Type
- capitalizeFirst :: String -> String
- lowerFirst :: String -> String
Documentation
Egison types
Constructors
| TInt | Integer |
| TMathExpr | MathExpr (mathematical expression, unifies with Integer) |
| TPolyExpr | PolyExpr (polynomial expression) |
| TTermExpr | TermExpr (term in polynomial) |
| TSymbolExpr | SymbolExpr (symbolic variable) |
| TIndexExpr | IndexExpr (subscript/superscript index) |
| TFloat | Float (Double) |
| TBool | Bool |
| TChar | Char |
| TString | String |
| TVar TyVar | Type variable, e.g., a |
| TTuple [Type] | Tuple type, e.g., (a, b). Unit type () is TTuple [] |
| TCollection Type | Collection type, e.g., [a] |
| TInductive String [Type] | Inductive data type with type arguments |
| TTensor Type | Tensor type (only element type is kept). Vector and Matrix are aliases for Tensor |
| THash Type Type | Hash map type |
| TMatcher Type | Matcher type, e.g., Matcher a |
| TFun Type Type | Function type, e.g., a -> b |
| TIO Type | IO type (for IO actions) |
| TIORef Type | IORef type |
| TPort | Port type (file handles) |
| TAny | Any type (for gradual typing) |
Instances
data TypeScheme Source #
Type scheme for polymorphic types (∀a. C a => Type) Includes type constraints for type class support
Constructors
| Forall [TyVar] [Constraint] Type |
Instances
| Generic TypeScheme Source # | |||||
Defined in Language.Egison.Type.Types Associated Types
| |||||
| Show TypeScheme Source # | |||||
Defined in Language.Egison.Type.Types Methods showsPrec :: Int -> TypeScheme -> ShowS # show :: TypeScheme -> String # showList :: [TypeScheme] -> ShowS # | |||||
| Eq TypeScheme Source # | |||||
Defined in Language.Egison.Type.Types | |||||
| type Rep TypeScheme Source # | |||||
Defined in Language.Egison.Type.Types type Rep TypeScheme = D1 ('MetaData "TypeScheme" "Language.Egison.Type.Types" "egison-5.0.0-IKLJXBVxR779jp4wYu1Icq" 'False) (C1 ('MetaCons "Forall" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TyVar]) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Constraint]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Type)))) | |||||
Type variable
Instances
| Generic TyVar Source # | |||||
Defined in Language.Egison.Type.Types Associated Types
| |||||
| Show TyVar Source # | |||||
| Eq TyVar Source # | |||||
| Ord TyVar Source # | |||||
| Hashable TyVar Source # | |||||
Defined in Language.Egison.Type.Types | |||||
| type Rep TyVar Source # | |||||
Defined in Language.Egison.Type.Types | |||||
data TensorShape Source #
Tensor shape (dimension sizes)
Constructors
| ShapeLit [Integer] | Concrete shape, e.g., [2, 2] |
| ShapeVar String | Shape variable, e.g., ns in zeroTensor |
| ShapeMixed [ShapeDimType] | Mixed shape, e.g., [n, m, 2] |
| ShapeUnknown | To be inferred |
Instances
| Generic TensorShape Source # | |||||
Defined in Language.Egison.Type.Types Associated Types
| |||||
| Show TensorShape Source # | |||||
Defined in Language.Egison.Type.Types Methods showsPrec :: Int -> TensorShape -> ShowS # show :: TensorShape -> String # showList :: [TensorShape] -> ShowS # | |||||
| Eq TensorShape Source # | |||||
Defined in Language.Egison.Type.Types | |||||
| Ord TensorShape Source # | |||||
Defined in Language.Egison.Type.Types Methods compare :: TensorShape -> TensorShape -> Ordering # (<) :: TensorShape -> TensorShape -> Bool # (<=) :: TensorShape -> TensorShape -> Bool # (>) :: TensorShape -> TensorShape -> Bool # (>=) :: TensorShape -> TensorShape -> Bool # max :: TensorShape -> TensorShape -> TensorShape # min :: TensorShape -> TensorShape -> TensorShape # | |||||
| Hashable TensorShape Source # | |||||
Defined in Language.Egison.Type.Types | |||||
| type Rep TensorShape Source # | |||||
Defined in Language.Egison.Type.Types type Rep TensorShape = D1 ('MetaData "TensorShape" "Language.Egison.Type.Types" "egison-5.0.0-IKLJXBVxR779jp4wYu1Icq" 'False) ((C1 ('MetaCons "ShapeLit" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Integer])) :+: C1 ('MetaCons "ShapeVar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))) :+: (C1 ('MetaCons "ShapeMixed" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [ShapeDimType])) :+: C1 ('MetaCons "ShapeUnknown" 'PrefixI 'False) (U1 :: Type -> Type))) | |||||
data ShapeDimType Source #
Shape dimension (can be concrete or variable)
Instances
| Generic ShapeDimType Source # | |||||
Defined in Language.Egison.Type.Types Associated Types
| |||||
| Show ShapeDimType Source # | |||||
Defined in Language.Egison.Type.Types Methods showsPrec :: Int -> ShapeDimType -> ShowS # show :: ShapeDimType -> String # showList :: [ShapeDimType] -> ShowS # | |||||
| Eq ShapeDimType Source # | |||||
Defined in Language.Egison.Type.Types | |||||
| Ord ShapeDimType Source # | |||||
Defined in Language.Egison.Type.Types Methods compare :: ShapeDimType -> ShapeDimType -> Ordering # (<) :: ShapeDimType -> ShapeDimType -> Bool # (<=) :: ShapeDimType -> ShapeDimType -> Bool # (>) :: ShapeDimType -> ShapeDimType -> Bool # (>=) :: ShapeDimType -> ShapeDimType -> Bool # max :: ShapeDimType -> ShapeDimType -> ShapeDimType # min :: ShapeDimType -> ShapeDimType -> ShapeDimType # | |||||
| Hashable ShapeDimType Source # | |||||
Defined in Language.Egison.Type.Types | |||||
| type Rep ShapeDimType Source # | |||||
Defined in Language.Egison.Type.Types type Rep ShapeDimType = D1 ('MetaData "ShapeDimType" "Language.Egison.Type.Types" "egison-5.0.0-IKLJXBVxR779jp4wYu1Icq" 'False) (C1 ('MetaCons "DimLit" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer)) :+: C1 ('MetaCons "DimVar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))) | |||||
data Constraint Source #
Type class constraint, e.g., "Eq a"
Constructors
| Constraint | |
Fields
| |
Instances
| Generic Constraint Source # | |||||
Defined in Language.Egison.Type.Types Associated Types
| |||||
| Show Constraint Source # | |||||
Defined in Language.Egison.Type.Types Methods showsPrec :: Int -> Constraint -> ShowS # show :: Constraint -> String # showList :: [Constraint] -> ShowS # | |||||
| Eq Constraint Source # | |||||
Defined in Language.Egison.Type.Types | |||||
| type Rep Constraint Source # | |||||
Defined in Language.Egison.Type.Types type Rep Constraint = D1 ('MetaData "Constraint" "Language.Egison.Type.Types" "egison-5.0.0-IKLJXBVxR779jp4wYu1Icq" 'False) (C1 ('MetaCons "Constraint" 'PrefixI 'True) (S1 ('MetaSel ('Just "constraintClass") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('Just "constraintType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Type))) | |||||
Information about a type class
Constructors
| ClassInfo | |
Fields
| |
Instances
| Generic ClassInfo Source # | |||||
Defined in Language.Egison.Type.Types Associated Types
| |||||
| Show ClassInfo Source # | |||||
| Eq ClassInfo Source # | |||||
| type Rep ClassInfo Source # | |||||
Defined in Language.Egison.Type.Types type Rep ClassInfo = D1 ('MetaData "ClassInfo" "Language.Egison.Type.Types" "egison-5.0.0-IKLJXBVxR779jp4wYu1Icq" 'False) (C1 ('MetaCons "ClassInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "classSupers") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [String]) :*: (S1 ('MetaSel ('Just "classParam") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TyVar) :*: S1 ('MetaSel ('Just "classMethods") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(String, Type)])))) | |||||
data InstanceInfo Source #
Information about a type class instance
Constructors
| InstanceInfo | |
Fields
| |
Instances
| Generic InstanceInfo Source # | |||||
Defined in Language.Egison.Type.Types Associated Types
| |||||
| Show InstanceInfo Source # | |||||
Defined in Language.Egison.Type.Types Methods showsPrec :: Int -> InstanceInfo -> ShowS # show :: InstanceInfo -> String # showList :: [InstanceInfo] -> ShowS # | |||||
| Eq InstanceInfo Source # | |||||
Defined in Language.Egison.Type.Types | |||||
| type Rep InstanceInfo Source # | |||||
Defined in Language.Egison.Type.Types type Rep InstanceInfo = D1 ('MetaData "InstanceInfo" "Language.Egison.Type.Types" "egison-5.0.0-IKLJXBVxR779jp4wYu1Icq" 'False) (C1 ('MetaCons "InstanceInfo" 'PrefixI 'True) ((S1 ('MetaSel ('Just "instContext") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Constraint]) :*: S1 ('MetaSel ('Just "instClass") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :*: (S1 ('MetaSel ('Just "instType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Type) :*: S1 ('MetaSel ('Just "instMethods") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(String, ())])))) | |||||
isTensorType :: Type -> Bool Source #
Check if a type is a tensor type
isScalarType :: Type -> Bool Source #
Check if a type is a scalar (non-tensor) type
typeToName :: Type -> String Source #
Convert a Type to a string name for dictionary and method naming This is used for generating instance dictionary names and method names E.g., TInt -> Integer, TTensor TInt -> TensorInteger
typeConstructorName :: Type -> String Source #
Get the type constructor name only, without type parameters Used for generating instance dictionary names (e.g., "eqCollection" not "eqCollectiona")
sanitizeMethodName :: String -> String Source #
Sanitize method names for use in identifiers Converts operator symbols to alphanumeric names E.g., "==" -> "eq", "+" -> "plus"
typeExprToType :: TypeExpr -> Type Source #
Convert TypeExpr (from AST) to Type (internal representation)
normalizeInductiveTypes :: Type -> Type Source #
Normalize inductive type names to primitive types if applicable This is used to convert TInductive MathExpr [] to TMathExpr, etc.
capitalizeFirst :: String -> String Source #
Capitalize first character
lowerFirst :: String -> String Source #
Lowercase first character