| License | MIT |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
Language.Egison.AST
Description
This module defines the syntax of Egison.
Synopsis
- data TopExpr
- = Define VarWithIndices Expr
- | DefineWithType TypedVarWithIndices Expr
- | Test Expr
- | Execute Expr
- | LoadFile String
- | Load String
- | InfixDecl Bool Op
- | InductiveDecl String [String] [InductiveConstructor]
- | ClassDeclExpr ClassDecl
- | InstanceDeclExpr InstanceDecl
- | PatternInductiveDecl String [String] [PatternConstructor]
- | PatternFunctionDecl String [String] [(String, TypeExpr)] TypeExpr Pattern
- | DeclareSymbol [String] (Maybe TypeExpr)
- data ConstantExpr
- data Expr
- = ConstantExpr ConstantExpr
- | VarExpr String
- | FreshVarExpr
- | IndexedExpr Bool Expr [IndexExpr Expr]
- | SubrefsExpr Bool Expr Expr
- | SuprefsExpr Bool Expr Expr
- | UserrefsExpr Bool Expr Expr
- | TupleExpr [Expr]
- | CollectionExpr [Expr]
- | ConsExpr Expr Expr
- | JoinExpr Expr Expr
- | HashExpr [(Expr, Expr)]
- | VectorExpr [Expr]
- | LambdaExpr [Arg ArgPattern] Expr
- | LambdaExpr' [Arg VarWithIndices] Expr
- | TypedLambdaExpr [(String, TypeExpr)] TypeExpr Expr
- | MemoizedLambdaExpr [String] Expr
- | TypedMemoizedLambdaExpr [TypedParam] TypeExpr Expr
- | CambdaExpr String Expr
- | PatternFunctionExpr [String] Pattern
- | IfExpr Expr Expr Expr
- | LetExpr [BindingExpr] Expr
- | LetRecExpr [BindingExpr] Expr
- | WithSymbolsExpr [String] Expr
- | MatchExpr PMMode Expr Expr [MatchClause]
- | MatchAllExpr PMMode Expr Expr [MatchClause]
- | MatchLambdaExpr Expr [MatchClause]
- | MatchAllLambdaExpr Expr [MatchClause]
- | MatcherExpr [PatternDef]
- | AlgebraicDataMatcherExpr [(String, [Expr])]
- | QuoteExpr Expr
- | QuoteSymbolExpr Expr
- | WedgeApplyExpr Expr [Expr]
- | DoExpr [BindingExpr] Expr
- | PrefixExpr String Expr
- | InfixExpr Op Expr Expr
- | SectionExpr Op (Maybe Expr) (Maybe Expr)
- | SeqExpr Expr Expr
- | ApplyExpr Expr [Expr]
- | AnonParamFuncExpr Integer Expr
- | AnonTupleParamFuncExpr Integer Expr
- | AnonListParamFuncExpr Integer Expr
- | AnonParamExpr Integer
- | GenerateTensorExpr Expr Expr
- | TensorExpr Expr Expr
- | TensorContractExpr Expr
- | TensorMapExpr Expr Expr
- | TensorMap2Expr Expr Expr Expr
- | TransposeExpr Expr Expr
- | FlipIndicesExpr Expr
- | FunctionExpr [String]
- | TypeAnnotation Expr TypeExpr
- data Pattern
- = WildCard
- | PatVar String
- | ValuePat Expr
- | PredPat Expr
- | IndexedPat Pattern [Expr]
- | LetPat [BindingExpr] Pattern
- | InfixPat Op Pattern Pattern
- | NotPat Pattern
- | AndPat Pattern Pattern
- | OrPat Pattern Pattern
- | ForallPat Pattern Pattern
- | TuplePat [Pattern]
- | InductivePat String [Pattern]
- | LoopPat String LoopRange Pattern Pattern
- | ContPat
- | PApplyPat Expr [Pattern]
- | VarPat String
- | InductiveOrPApplyPat String [Pattern]
- | SeqNilPat
- | SeqConsPat Pattern Pattern
- | LaterPatVar
- | DApplyPat Pattern [Pattern]
- data VarWithIndices = VarWithIndices String [VarIndex]
- makeApply :: String -> [Expr] -> Expr
- data Arg a
- = Arg a
- | InvertedArg a
- data ArgPattern
- data IndexExpr a
- = Subscript a
- | Superscript a
- | SupSubscript a
- | MultiSubscript a a
- | MultiSuperscript a a
- | Userscript a
- data VarIndex
- data PMMode
- data BindingExpr
- type MatchClause = (Pattern, Expr)
- data PatternDef = PatternDef {}
- data LoopRange = LoopRange Expr Expr Pattern
- data PrimitivePatPattern
- data PDPatternBase var
- = PDWildCard
- | PDPatVar var
- | PDInductivePat String [PDPatternBase var]
- | PDTuplePat [PDPatternBase var]
- | PDEmptyPat
- | PDConsPat (PDPatternBase var) (PDPatternBase var)
- | PDSnocPat (PDPatternBase var) (PDPatternBase var)
- | PDConstantPat ConstantExpr
- | PDDivPat (PDPatternBase var) (PDPatternBase var)
- | PDPlusPat (PDPatternBase var)
- | PDTermPat (PDPatternBase var) (PDPatternBase var)
- | PDSymbolPat (PDPatternBase var) (PDPatternBase var)
- | PDApply1Pat (PDPatternBase var) (PDPatternBase var)
- | PDApply2Pat (PDPatternBase var) (PDPatternBase var) (PDPatternBase var)
- | PDApply3Pat (PDPatternBase var) (PDPatternBase var) (PDPatternBase var) (PDPatternBase var)
- | PDApply4Pat (PDPatternBase var) (PDPatternBase var) (PDPatternBase var) (PDPatternBase var) (PDPatternBase var)
- | PDQuotePat (PDPatternBase var)
- | PDFunctionPat (PDPatternBase var) (PDPatternBase var)
- | PDSubPat (PDPatternBase var)
- | PDSupPat (PDPatternBase var)
- | PDUserPat (PDPatternBase var)
- type PrimitiveDataPattern = PDPatternBase String
- data Op = Op {}
- data Assoc
- reservedExprOp :: [Op]
- reservedPatternOp :: [Op]
- findOpFrom :: String -> [Op] -> Op
- stringToVarWithIndices :: String -> VarWithIndices
- extractNameFromVarWithIndices :: VarWithIndices -> String
- data TypeExpr
- = TEInt
- | TEMathExpr
- | TEFloat
- | TEBool
- | TEChar
- | TEString
- | TEVar String
- | TEList TypeExpr
- | TETuple [TypeExpr]
- | TEFun TypeExpr TypeExpr
- | TEMatcher TypeExpr
- | TEPattern TypeExpr
- | TEIO TypeExpr
- | TETensor TypeExpr
- | TEVector TypeExpr
- | TEMatrix TypeExpr
- | TEDiffForm TypeExpr
- | TEApp TypeExpr [TypeExpr]
- | TEConstrained [ConstraintExpr] TypeExpr
- data TensorShapeExpr
- data ShapeDim
- data TensorIndexExpr
- data TypedParam
- data TypedVarWithIndices = TypedVarWithIndices {}
- data InductiveConstructor = InductiveConstructor {}
- data PatternConstructor = PatternConstructor {}
- data ClassDecl = ClassDecl {}
- data ClassMethod = ClassMethod {}
- data InstanceDecl = InstanceDecl {}
- data InstanceMethod = InstanceMethod {}
- data ConstraintExpr = ConstraintExpr {}
Documentation
Constructors
| Define VarWithIndices Expr | |
| DefineWithType TypedVarWithIndices Expr | Definition with type annotation |
| Test Expr | |
| Execute Expr | |
| LoadFile String | |
| Load String | |
| InfixDecl Bool Op | |
| InductiveDecl String [String] [InductiveConstructor] | Inductive data type declaration with type parameters e.g., inductive Ordering := | Less | Equal | Greater inductive Maybe a := | Nothing | Just a String: type name, [String]: type parameters, [InductiveConstructor]: constructors |
| ClassDeclExpr ClassDecl | Type class declaration e.g., class Eq a where (==) (x: a) (y: a) : Bool |
| InstanceDeclExpr InstanceDecl | Type class instance declaration e.g., instance Eq Integer where (==) x y := x = y |
| PatternInductiveDecl String [String] [PatternConstructor] | Pattern inductive type declaration e.g., inductive pattern MyList a := | myNil | myCons a (MyList a) String: pattern type name, [String]: type parameters, [PatternConstructor]: constructors |
| PatternFunctionDecl String [String] [(String, TypeExpr)] TypeExpr Pattern | Pattern function declaration e.g., def pattern twin {a} (p1 : a) (p2 : MyList a) : MyList a := ... String: function name, [String]: type parameters, [(String, TypeExpr)]: parameters, TypeExpr: return type, Pattern: body |
| DeclareSymbol [String] (Maybe TypeExpr) | Symbol declaration e.g., declare symbol a11, a12, a21, a22 declare symbol x, y, z : Float [String]: symbol names, Maybe TypeExpr: optional type (defaults to Integer) |
data ConstantExpr Source #
Constructors
| CharExpr Char | |
| StringExpr Text | |
| BoolExpr Bool | |
| IntegerExpr Integer | |
| FloatExpr Double | |
| SomethingExpr | |
| UndefinedExpr |
Instances
| Show ConstantExpr Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> ConstantExpr -> ShowS # show :: ConstantExpr -> String # showList :: [ConstantExpr] -> ShowS # | |
| Pretty ConstantExpr Source # | |
Defined in Language.Egison.Pretty | |
Constructors
Instances
| Show Expr Source # | |
| Pretty Expr Source # | |
Defined in Language.Egison.Pretty | |
| Pretty MatchClause Source # | |
Defined in Language.Egison.Pretty | |
Constructors
Instances
| Show Pattern Source # | |
| Pretty MatchClause Source # | |
Defined in Language.Egison.Pretty | |
| Pretty Pattern Source # | |
Defined in Language.Egison.Pretty | |
data VarWithIndices Source #
Constructors
| VarWithIndices String [VarIndex] |
Instances
| Show VarWithIndices Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> VarWithIndices -> ShowS # show :: VarWithIndices -> String # showList :: [VarWithIndices] -> ShowS # | |
| Eq VarWithIndices Source # | |
Defined in Language.Egison.AST Methods (==) :: VarWithIndices -> VarWithIndices -> Bool # (/=) :: VarWithIndices -> VarWithIndices -> Bool # | |
| Pretty VarWithIndices Source # | |
Defined in Language.Egison.Pretty | |
Constructors
| Arg a | |
| InvertedArg a |
data ArgPattern Source #
Constructors
| APWildCard | |
| APPatVar VarWithIndices | |
| APInductivePat String [Arg ArgPattern] | |
| APTuplePat [Arg ArgPattern] | |
| APEmptyPat | |
| APConsPat (Arg ArgPattern) ArgPattern | |
| APSnocPat ArgPattern (Arg ArgPattern) |
Instances
| Show ArgPattern Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> ArgPattern -> ShowS # show :: ArgPattern -> String # showList :: [ArgPattern] -> ShowS # | |
| Pretty ArgPattern Source # | |
Defined in Language.Egison.Pretty | |
Constructors
| Subscript a | |
| Superscript a | |
| SupSubscript a | |
| MultiSubscript a a | |
| MultiSuperscript a a | |
| Userscript a |
Instances
| Foldable IndexExpr Source # | |
Defined in Language.Egison.AST Methods fold :: Monoid m => IndexExpr m -> m # foldMap :: Monoid m => (a -> m) -> IndexExpr a -> m # foldMap' :: Monoid m => (a -> m) -> IndexExpr a -> m # foldr :: (a -> b -> b) -> b -> IndexExpr a -> b # foldr' :: (a -> b -> b) -> b -> IndexExpr a -> b # foldl :: (b -> a -> b) -> b -> IndexExpr a -> b # foldl' :: (b -> a -> b) -> b -> IndexExpr a -> b # foldr1 :: (a -> a -> a) -> IndexExpr a -> a # foldl1 :: (a -> a -> a) -> IndexExpr a -> a # toList :: IndexExpr a -> [a] # length :: IndexExpr a -> Int # elem :: Eq a => a -> IndexExpr a -> Bool # maximum :: Ord a => IndexExpr a -> a # minimum :: Ord a => IndexExpr a -> a # | |
| Traversable IndexExpr Source # | |
Defined in Language.Egison.AST | |
| Functor IndexExpr Source # | |
| Show a => Show (IndexExpr a) Source # | |
| Eq a => Eq (IndexExpr a) Source # | |
| Pretty (IndexExpr String) Source # | |
| (Pretty a, Complex a) => Pretty (IndexExpr a) Source # | |
Defined in Language.Egison.Pretty | |
Constructors
| VSubscript String | |
| VSuperscript String | |
| VMultiSubscript String Integer String | |
| VMultiSuperscript String Integer String | |
| VGroupScripts [VarIndex] | |
| VSymmScripts [VarIndex] | |
| VAntiSymmScripts [VarIndex] |
data BindingExpr Source #
Constructors
| Bind PrimitiveDataPattern Expr | |
| BindWithIndices VarWithIndices Expr | |
| BindWithType TypedVarWithIndices Expr | Binding with type annotation (for where clauses) |
Instances
| Show BindingExpr Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> BindingExpr -> ShowS # show :: BindingExpr -> String # showList :: [BindingExpr] -> ShowS # | |
| Pretty BindingExpr Source # | |
Defined in Language.Egison.Pretty | |
type MatchClause = (Pattern, Expr) Source #
data PatternDef Source #
Pattern definition in a matcher (with optional type class constraints)
Constructors
| PatternDef | |
Fields | |
Instances
| Show PatternDef Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> PatternDef -> ShowS # show :: PatternDef -> String # showList :: [PatternDef] -> ShowS # | |
data PrimitivePatPattern Source #
Constructors
| PPWildCard | |
| PPPatVar | |
| PPValuePat String | |
| PPInductivePat String [PrimitivePatPattern] | |
| PPTuplePat [PrimitivePatPattern] |
Instances
| Show PrimitivePatPattern Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> PrimitivePatPattern -> ShowS # show :: PrimitivePatPattern -> String # showList :: [PrimitivePatPattern] -> ShowS # | |
| Pretty PrimitivePatPattern Source # | |
Defined in Language.Egison.Pretty | |
data PDPatternBase var Source #
Constructors
| PDWildCard | |
| PDPatVar var | |
| PDInductivePat String [PDPatternBase var] | |
| PDTuplePat [PDPatternBase var] | |
| PDEmptyPat | |
| PDConsPat (PDPatternBase var) (PDPatternBase var) | |
| PDSnocPat (PDPatternBase var) (PDPatternBase var) | |
| PDConstantPat ConstantExpr | |
| PDDivPat (PDPatternBase var) (PDPatternBase var) | |
| PDPlusPat (PDPatternBase var) | |
| PDTermPat (PDPatternBase var) (PDPatternBase var) | |
| PDSymbolPat (PDPatternBase var) (PDPatternBase var) | |
| PDApply1Pat (PDPatternBase var) (PDPatternBase var) | |
| PDApply2Pat (PDPatternBase var) (PDPatternBase var) (PDPatternBase var) | |
| PDApply3Pat (PDPatternBase var) (PDPatternBase var) (PDPatternBase var) (PDPatternBase var) | |
| PDApply4Pat (PDPatternBase var) (PDPatternBase var) (PDPatternBase var) (PDPatternBase var) (PDPatternBase var) | |
| PDQuotePat (PDPatternBase var) | |
| PDFunctionPat (PDPatternBase var) (PDPatternBase var) | |
| PDSubPat (PDPatternBase var) | |
| PDSupPat (PDPatternBase var) | |
| PDUserPat (PDPatternBase var) |
Instances
reservedExprOp :: [Op] Source #
reservedPatternOp :: [Op] Source #
Type expression in source code
Constructors
| TEInt | Integer (= MathExpr) |
| TEMathExpr | MathExpr (= Integer) |
| TEFloat | Float |
| TEBool | Bool |
| TEChar | Char |
| TEString | String |
| TEVar String | Type variable, e.g., a |
| TEList TypeExpr | List type, e.g., [a] |
| TETuple [TypeExpr] | Tuple type, e.g., (a, b) |
| TEFun TypeExpr TypeExpr | Function type, e.g., a -> b |
| TEMatcher TypeExpr | Matcher type |
| TEPattern TypeExpr | Pattern type, e.g., Pattern a |
| TEIO TypeExpr | IO type, e.g., IO () |
| TETensor TypeExpr | Tensor type, e.g., Tensor a |
| TEVector TypeExpr | Vector type, e.g., Vector a (1D tensor) |
| TEMatrix TypeExpr | Matrix type, e.g., Matrix a (2D tensor) |
| TEDiffForm TypeExpr | DiffForm type, e.g., DiffForm a (differential form, alias for Tensor) |
| TEApp TypeExpr [TypeExpr] | Type application, e.g., List a |
| TEConstrained [ConstraintExpr] TypeExpr | Constrained type, e.g., Eq a => a |
data TensorShapeExpr Source #
Tensor shape expression
Constructors
| TSLit [Integer] | Concrete shape, e.g., [2, 2] |
| TSVar String | Shape variable |
| TSMixed [ShapeDim] | Mixed shape, e.g., [n, m, 2] |
Instances
| Show TensorShapeExpr Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> TensorShapeExpr -> ShowS # show :: TensorShapeExpr -> String # showList :: [TensorShapeExpr] -> ShowS # | |
| Eq TensorShapeExpr Source # | |
Defined in Language.Egison.AST Methods (==) :: TensorShapeExpr -> TensorShapeExpr -> Bool # (/=) :: TensorShapeExpr -> TensorShapeExpr -> Bool # | |
Shape dimension (can be concrete or variable)
Instances
data TensorIndexExpr Source #
Tensor index expression
Constructors
| TISub String | Subscript, e.g., _i |
| TISup String | Superscript, e.g., ~i |
| TIPlaceholderSub | Subscript placeholder, _# |
| TIPlaceholderSup | Superscript placeholder, ~# |
Instances
| Show TensorIndexExpr Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> TensorIndexExpr -> ShowS # show :: TensorIndexExpr -> String # showList :: [TensorIndexExpr] -> ShowS # | |
| Eq TensorIndexExpr Source # | |
Defined in Language.Egison.AST Methods (==) :: TensorIndexExpr -> TensorIndexExpr -> Bool # (/=) :: TensorIndexExpr -> TensorIndexExpr -> Bool # | |
data TypedParam Source #
Typed parameter pattern
Constructors
| TPVar String TypeExpr | Simple variable with type: (x: a) |
| TPInvertedVar String TypeExpr | Inverted variable with type: (!x: a) |
| TPTuple [TypedParam] | Tuple pattern: ((x: a), (y: b)) or (x: a, y: b) |
| TPWildcard TypeExpr | Wildcard with type: (_: a) |
| TPUntypedVar String | Untyped variable in tuple: x (inferred) |
| TPUntypedWildcard | Untyped wildcard: _ |
Instances
| Show TypedParam Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> TypedParam -> ShowS # show :: TypedParam -> String # showList :: [TypedParam] -> ShowS # | |
| Eq TypedParam Source # | |
Defined in Language.Egison.AST | |
| Pretty TypedParam Source # | |
Defined in Language.Egison.Pretty | |
data TypedVarWithIndices Source #
Variable with type annotation
Constructors
| TypedVarWithIndices | |
Fields
| |
Instances
| Show TypedVarWithIndices Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> TypedVarWithIndices -> ShowS # show :: TypedVarWithIndices -> String # showList :: [TypedVarWithIndices] -> ShowS # | |
| Eq TypedVarWithIndices Source # | |
Defined in Language.Egison.AST Methods (==) :: TypedVarWithIndices -> TypedVarWithIndices -> Bool # (/=) :: TypedVarWithIndices -> TypedVarWithIndices -> Bool # | |
data InductiveConstructor Source #
Constructor for inductive data type e.g., Less, S Nat, Node Tree Tree
Constructors
| InductiveConstructor | |
Fields
| |
Instances
| Show InductiveConstructor Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> InductiveConstructor -> ShowS # show :: InductiveConstructor -> String # showList :: [InductiveConstructor] -> ShowS # | |
| Eq InductiveConstructor Source # | |
Defined in Language.Egison.AST Methods (==) :: InductiveConstructor -> InductiveConstructor -> Bool # (/=) :: InductiveConstructor -> InductiveConstructor -> Bool # | |
data PatternConstructor Source #
Constructor for pattern inductive type e.g., myNil, myCons a (MyList a)
Constructors
| PatternConstructor | |
Fields
| |
Instances
| Show PatternConstructor Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> PatternConstructor -> ShowS # show :: PatternConstructor -> String # showList :: [PatternConstructor] -> ShowS # | |
| Eq PatternConstructor Source # | |
Defined in Language.Egison.AST Methods (==) :: PatternConstructor -> PatternConstructor -> Bool # (/=) :: PatternConstructor -> PatternConstructor -> Bool # | |
Type class declaration e.g., class Eq a where ... class Eq a => Ord a where ...
Constructors
| ClassDecl | |
Fields
| |
data ClassMethod Source #
Type class method declaration e.g., (==) (x: a) (y: a) : Bool (/=) (x: a) (y: a) : Bool := not (x == y)
Constructors
| ClassMethod | |
Fields
| |
Instances
| Show ClassMethod Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> ClassMethod -> ShowS # show :: ClassMethod -> String # showList :: [ClassMethod] -> ShowS # | |
data InstanceDecl Source #
Type class instance declaration e.g., instance Eq Integer where ... instance Eq a => Eq [a] where ...
Constructors
| InstanceDecl | |
Fields
| |
Instances
| Show InstanceDecl Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> InstanceDecl -> ShowS # show :: InstanceDecl -> String # showList :: [InstanceDecl] -> ShowS # | |
data InstanceMethod Source #
Instance method implementation e.g., (==) x y := x = y
Constructors
| InstanceMethod | |
Fields
| |
Instances
| Show InstanceMethod Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> InstanceMethod -> ShowS # show :: InstanceMethod -> String # showList :: [InstanceMethod] -> ShowS # | |
data ConstraintExpr Source #
Type constraint expression e.g., Eq a, Ord a
Constructors
| ConstraintExpr | |
Fields
| |
Instances
| Show ConstraintExpr Source # | |
Defined in Language.Egison.AST Methods showsPrec :: Int -> ConstraintExpr -> ShowS # show :: ConstraintExpr -> String # showList :: [ConstraintExpr] -> ShowS # | |
| Eq ConstraintExpr Source # | |
Defined in Language.Egison.AST Methods (==) :: ConstraintExpr -> ConstraintExpr -> Bool # (/=) :: ConstraintExpr -> ConstraintExpr -> Bool # | |
| Pretty ConstraintExpr Source # | |
Defined in Language.Egison.Pretty | |