module Language.Egison.Type.Check
(
builtinEnv
) where
import Language.Egison.IExpr (stringToVar)
import Language.Egison.Type.Env
import Language.Egison.Type.Types
builtinEnv :: TypeEnv
builtinEnv :: TypeEnv
builtinEnv = [(Var, TypeScheme)] -> TypeEnv -> TypeEnv
extendEnvMany (((String, TypeScheme) -> (Var, TypeScheme))
-> [(String, TypeScheme)] -> [(Var, TypeScheme)]
forall a b. (a -> b) -> [a] -> [b]
map (\(String
name, TypeScheme
scheme) -> (String -> Var
stringToVar String
name, TypeScheme
scheme)) [(String, TypeScheme)]
builtinTypes) TypeEnv
emptyEnv
builtinTypes :: [(String, TypeScheme)]
builtinTypes :: [(String, TypeScheme)]
builtinTypes = [[(String, TypeScheme)]] -> [(String, TypeScheme)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ [(String, TypeScheme)]
constantsTypes
, [(String, TypeScheme)]
primitivesTypes
, [(String, TypeScheme)]
arithTypes
, [(String, TypeScheme)]
stringTypes
, [(String, TypeScheme)]
typeFunctionsTypes
, [(String, TypeScheme)]
ioTypes
, [(String, TypeScheme)]
matcherTypes
, [(String, TypeScheme)]
utilityTypes
]
where
a :: TyVar
a = String -> TyVar
TyVar String
"a"
binOpT :: Type -> Type -> Type -> Type
binOpT :: Type -> Type -> Type -> Type
binOpT Type
t1 Type
t2 Type
t3 = Type -> Type -> Type
TFun Type
t1 (Type -> Type -> Type
TFun Type
t2 Type
t3)
ternOpT :: Type -> Type -> Type -> Type -> Type
ternOpT :: Type -> Type -> Type -> Type -> Type
ternOpT Type
t1 Type
t2 Type
t3 Type
t4 = Type -> Type -> Type
TFun Type
t1 (Type -> Type -> Type
TFun Type
t2 (Type -> Type -> Type
TFun Type
t3 Type
t4))
binOp :: Type -> Type -> Type -> TypeScheme
binOp :: Type -> Type -> Type -> TypeScheme
binOp Type
t1 Type
t2 Type
t3 = [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type -> Type
binOpT Type
t1 Type
t2 Type
t3
unaryOp :: Type -> Type -> TypeScheme
unaryOp :: Type -> Type -> TypeScheme
unaryOp Type
t1 Type
t2 = [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun Type
t1 Type
t2
forallA :: Type -> TypeScheme
forallA :: Type -> TypeScheme
forallA = [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [TyVar
a] []
forallABinOp :: Type -> Type -> Type -> TypeScheme
forallABinOp :: Type -> Type -> Type -> TypeScheme
forallABinOp Type
t1 Type
t2 Type
t3 = [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [TyVar
a] [] (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type -> Type
binOpT Type
t1 Type
t2 Type
t3
constantsTypes :: [(String, TypeScheme)]
constantsTypes =
[ (String
"f.pi", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] Type
TFloat)
, (String
"f.e", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] Type
TFloat)
]
primitivesTypes :: [(String, TypeScheme)]
primitivesTypes =
[ (String
"addSubscript", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TInt)
, (String
"addSuperscript", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TInt)
, (String
"assert", Type -> Type -> Type -> TypeScheme
binOp Type
TString Type
TBool Type
TBool)
, (String
"assertEqual", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type -> Type -> Type
ternOpT Type
TString (TyVar -> Type
TVar TyVar
a) (TyVar -> Type
TVar TyVar
a) Type
TBool)
, (String
"sortWithSign", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (Type -> Type
TCollection (Type -> Type
TCollection Type
TInt)) ([Type] -> Type
TTuple [Type
TInt, Type -> Type
TCollection Type
TInt]))
, (String
"updateFunctionArgs", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun Type
TMathExpr (Type -> Type -> Type
TFun (Type -> Type
TCollection Type
TMathExpr) Type
TMathExpr))
, (String
"tensorShape", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (Type -> Type
TTensor (TyVar -> Type
TVar TyVar
a)) (Type -> Type
TCollection Type
TInt))
, (String
"tensorToList", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (Type -> Type
TTensor (TyVar -> Type
TVar TyVar
a)) (Type -> Type
TCollection (TyVar -> Type
TVar TyVar
a)))
, (String
"dfOrder", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (Type -> Type
TTensor (TyVar -> Type
TVar TyVar
a)) Type
TInt)
]
arithTypes :: [(String, TypeScheme)]
arithTypes =
[
(String
"i.+", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TInt)
, (String
"i.-", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TInt)
, (String
"i.*", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TInt)
, (String
"i./", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TInt)
, (String
"f.+", Type -> Type -> Type -> TypeScheme
binOp Type
TFloat Type
TFloat Type
TFloat)
, (String
"f.-", Type -> Type -> Type -> TypeScheme
binOp Type
TFloat Type
TFloat Type
TFloat)
, (String
"f.*", Type -> Type -> Type -> TypeScheme
binOp Type
TFloat Type
TFloat Type
TFloat)
, (String
"f./", Type -> Type -> Type -> TypeScheme
binOp Type
TFloat Type
TFloat Type
TFloat)
, (String
"numerator", Type -> Type -> TypeScheme
unaryOp Type
TInt Type
TInt)
, (String
"denominator", Type -> Type -> TypeScheme
unaryOp Type
TInt Type
TInt)
, (String
"fromMathExpr", Type -> Type -> TypeScheme
unaryOp Type
TInt (String -> [Type] -> Type
TInductive String
"MathExpr'" []))
, (String
"toMathExpr'", Type -> Type -> TypeScheme
unaryOp (String -> [Type] -> Type
TInductive String
"MathExpr'" []) Type
TInt)
, (String
"symbolNormalize", Type -> Type -> TypeScheme
unaryOp Type
TInt Type
TInt)
, (String
"i.modulo", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TInt)
, (String
"i.quotient", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TInt)
, (String
"i.%", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TInt)
, (String
"i.power", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TInt)
, (String
"i.abs", Type -> Type -> TypeScheme
unaryOp Type
TInt Type
TInt)
, (String
"i.neg", Type -> Type -> TypeScheme
unaryOp Type
TInt Type
TInt)
, (String
"f.abs", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.neg", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"=", Type -> Type -> Type -> TypeScheme
forallABinOp (TyVar -> Type
TVar TyVar
a) (TyVar -> Type
TVar TyVar
a) Type
TBool)
, (String
"<", Type -> Type -> Type -> TypeScheme
forallABinOp (TyVar -> Type
TVar TyVar
a) (TyVar -> Type
TVar TyVar
a) Type
TBool)
, (String
"<=", Type -> Type -> Type -> TypeScheme
forallABinOp (TyVar -> Type
TVar TyVar
a) (TyVar -> Type
TVar TyVar
a) Type
TBool)
, (String
">", Type -> Type -> Type -> TypeScheme
forallABinOp (TyVar -> Type
TVar TyVar
a) (TyVar -> Type
TVar TyVar
a) Type
TBool)
, (String
">=", Type -> Type -> Type -> TypeScheme
forallABinOp (TyVar -> Type
TVar TyVar
a) (TyVar -> Type
TVar TyVar
a) Type
TBool)
, (String
"i.<", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TBool)
, (String
"i.<=", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TBool)
, (String
"i.>", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TBool)
, (String
"i.>=", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt Type
TBool)
, (String
"f.<", Type -> Type -> Type -> TypeScheme
binOp Type
TFloat Type
TFloat Type
TBool)
, (String
"f.<=", Type -> Type -> Type -> TypeScheme
binOp Type
TFloat Type
TFloat Type
TBool)
, (String
"f.>", Type -> Type -> Type -> TypeScheme
binOp Type
TFloat Type
TFloat Type
TBool)
, (String
"f.>=", Type -> Type -> Type -> TypeScheme
binOp Type
TFloat Type
TFloat Type
TBool)
, (String
"round", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TInt)
, (String
"floor", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TInt)
, (String
"ceiling", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TInt)
, (String
"truncate", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TInt)
, (String
"f.sqrt", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.sqrt'", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.exp", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.log", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.sin", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.cos", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.tan", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.asin", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.acos", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.atan", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.sinh", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.cosh", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.tanh", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.asinh", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.acosh", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
, (String
"f.atanh", Type -> Type -> TypeScheme
unaryOp Type
TFloat Type
TFloat)
]
ioTypes :: [(String, TypeScheme)]
ioTypes =
[ (String
"return", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (TyVar -> Type
TVar TyVar
a) (Type -> Type
TIO (TyVar -> Type
TVar TyVar
a)))
, (String
"io", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (Type -> Type
TIO (TyVar -> Type
TVar TyVar
a)) (TyVar -> Type
TVar TyVar
a))
, (String
"openInputFile", Type -> Type -> TypeScheme
unaryOp Type
TString (Type -> Type
TIO Type
TPort))
, (String
"openOutputFile", Type -> Type -> TypeScheme
unaryOp Type
TString (Type -> Type
TIO Type
TPort))
, (String
"closeInputPort", Type -> Type -> TypeScheme
unaryOp Type
TPort (Type -> Type
TIO ([Type] -> Type
TTuple [])))
, (String
"closeOutputPort", Type -> Type -> TypeScheme
unaryOp Type
TPort (Type -> Type
TIO ([Type] -> Type
TTuple [])))
, (String
"readChar", Type -> Type -> TypeScheme
unaryOp ([Type] -> Type
TTuple []) (Type -> Type
TIO Type
TChar))
, (String
"readLine", Type -> Type -> TypeScheme
unaryOp ([Type] -> Type
TTuple []) (Type -> Type
TIO Type
TString))
, (String
"writeChar", Type -> Type -> TypeScheme
unaryOp Type
TChar (Type -> Type
TIO ([Type] -> Type
TTuple [])))
, (String
"write", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (TyVar -> Type
TVar TyVar
a) (Type -> Type
TIO ([Type] -> Type
TTuple [])))
, (String
"readCharFromPort", Type -> Type -> TypeScheme
unaryOp Type
TPort (Type -> Type
TIO Type
TChar))
, (String
"readLineFromPort", Type -> Type -> TypeScheme
unaryOp Type
TPort (Type -> Type
TIO Type
TString))
, (String
"writeCharToPort", Type -> Type -> Type -> TypeScheme
binOp Type
TPort Type
TChar (Type -> Type
TIO ([Type] -> Type
TTuple [])))
, (String
"writeToPort", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type -> Type
binOpT Type
TPort (TyVar -> Type
TVar TyVar
a) (Type -> Type
TIO ([Type] -> Type
TTuple [])))
, (String
"readFile", Type -> Type -> TypeScheme
unaryOp Type
TString (Type -> Type
TIO Type
TString))
, (String
"isEof", Type -> Type -> TypeScheme
unaryOp ([Type] -> Type
TTuple []) (Type -> Type
TIO Type
TBool))
, (String
"isEofPort", Type -> Type -> TypeScheme
unaryOp Type
TPort (Type -> Type
TIO Type
TBool))
, (String
"flush", Type -> Type -> TypeScheme
unaryOp ([Type] -> Type
TTuple []) (Type -> Type
TIO ([Type] -> Type
TTuple [])))
, (String
"flushPort", Type -> Type -> TypeScheme
unaryOp Type
TPort (Type -> Type
TIO ([Type] -> Type
TTuple [])))
, (String
"rand", Type -> Type -> Type -> TypeScheme
binOp Type
TInt Type
TInt (Type -> Type
TIO Type
TInt))
, (String
"f.rand", Type -> Type -> Type -> TypeScheme
binOp Type
TFloat Type
TFloat (Type -> Type
TIO Type
TFloat))
, (String
"newIORef", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (TyVar -> Type
TVar TyVar
a) (Type -> Type
TIO (Type -> Type
TIORef (TyVar -> Type
TVar TyVar
a))))
, (String
"writeIORef", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type -> Type
binOpT (Type -> Type
TIORef (TyVar -> Type
TVar TyVar
a)) (TyVar -> Type
TVar TyVar
a) (Type -> Type
TIO ([Type] -> Type
TTuple [])))
, (String
"readIORef", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (Type -> Type
TIORef (TyVar -> Type
TVar TyVar
a)) (Type -> Type
TIO (TyVar -> Type
TVar TyVar
a)))
, (String
"readProcess", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [TyVar
a] [] (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type -> Type -> Type
ternOpT Type
TString (Type -> Type
TCollection Type
TString) Type
TString (Type -> Type
TIO Type
TString))
]
typeFunctionsTypes :: [(String, TypeScheme)]
typeFunctionsTypes =
[ (String
"itof", Type -> Type -> TypeScheme
unaryOp Type
TInt Type
TFloat)
, (String
"rtof", Type -> Type -> TypeScheme
unaryOp Type
TInt Type
TFloat)
, (String
"ctoi", Type -> Type -> TypeScheme
unaryOp Type
TChar Type
TInt)
, (String
"itoc", Type -> Type -> TypeScheme
unaryOp Type
TInt Type
TChar)
, (String
"isInteger", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (TyVar -> Type
TVar TyVar
a) Type
TBool)
, (String
"isRational", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (TyVar -> Type
TVar TyVar
a) Type
TBool)
]
matcherTypes :: [(String, TypeScheme)]
matcherTypes =
[ (String
"something", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type
TMatcher (TyVar -> Type
TVar TyVar
a))
]
stringTypes :: [(String, TypeScheme)]
stringTypes =
[ (String
"pack", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (Type -> Type
TCollection Type
TChar) Type
TString)
, (String
"unpack", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun Type
TString (Type -> Type
TCollection Type
TChar))
, (String
"unconsString", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun Type
TString ([Type] -> Type
TTuple [Type
TChar, Type
TString]))
, (String
"lengthString", Type -> Type -> TypeScheme
unaryOp Type
TString Type
TInt)
, (String
"appendString", Type -> Type -> Type -> TypeScheme
binOp Type
TString Type
TString Type
TString)
, (String
"splitString", Type -> Type -> Type -> TypeScheme
binOp Type
TString Type
TString (Type -> Type
TCollection Type
TString))
, (String
"regex", Type -> Type -> Type -> TypeScheme
binOp Type
TString Type
TString (Type -> Type
TCollection ([Type] -> Type
TTuple [Type
TString, Type
TString, Type
TString])))
, (String
"regexCg", Type -> Type -> Type -> TypeScheme
binOp Type
TString Type
TString (Type -> Type
TCollection ([Type] -> Type
TTuple [Type
TString, Type -> Type
TCollection Type
TString, Type
TString])))
, (String
"read", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] (Type -> Type
TIO Type
TString))
, (String
"readTsv", Type -> Type -> TypeScheme
unaryOp Type
TString (TyVar -> Type
TVar TyVar
a))
, (String
"show", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (TyVar -> Type
TVar TyVar
a) Type
TString)
, (String
"showTsv", Type -> TypeScheme
forallA (Type -> TypeScheme) -> Type -> TypeScheme
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
TFun (TyVar -> Type
TVar TyVar
a) Type
TString)
]
utilityTypes :: [(String, TypeScheme)]
utilityTypes =
[
(String
"True", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] Type
TBool)
, (String
"False", [TyVar] -> [Constraint] -> Type -> TypeScheme
Forall [] [] Type
TBool)
]