{- |
Module      : Language.Egison.Primitives.Types
Licence     : MIT

This module implements primitive functions that dynamically checks the types of
objects.
-}

module Language.Egison.Primitives.Types
  ( primitiveTypeFunctions
  ) where

import           Data.Char                        (chr, ord)
import           Data.Ratio                       ((%))

import           Language.Egison.Data
import           Language.Egison.Math
import           Language.Egison.Primitives.Utils

primitiveTypeFunctions :: [(String, EgisonValue)]
primitiveTypeFunctions :: [(String, EgisonValue)]
primitiveTypeFunctions =
  ((String, String -> PrimitiveFunc) -> (String, EgisonValue))
-> [(String, String -> PrimitiveFunc)] -> [(String, EgisonValue)]
forall a b. (a -> b) -> [a] -> [b]
map (\(String
name, String -> PrimitiveFunc
fn) -> (String
name, PrimitiveFunc -> EgisonValue
PrimitiveFunc (String -> PrimitiveFunc
fn String
name))) [(String, String -> PrimitiveFunc)]
strictPrimitives [(String, EgisonValue)]
-> [(String, EgisonValue)] -> [(String, EgisonValue)]
forall a. [a] -> [a] -> [a]
++
    ((String, String -> LazyPrimitiveFunc) -> (String, EgisonValue))
-> [(String, String -> LazyPrimitiveFunc)]
-> [(String, EgisonValue)]
forall a b. (a -> b) -> [a] -> [b]
map (\(String
name, String -> LazyPrimitiveFunc
fn) -> (String
name, LazyPrimitiveFunc -> EgisonValue
LazyPrimitiveFunc (String -> LazyPrimitiveFunc
fn String
name))) [(String, String -> LazyPrimitiveFunc)]
lazyPrimitives

strictPrimitives :: [(String, String -> PrimitiveFunc)]
strictPrimitives :: [(String, String -> PrimitiveFunc)]
strictPrimitives =
  [ (String
"itof", String -> PrimitiveFunc
integerToFloat)
  , (String
"rtof", String -> PrimitiveFunc
rationalToFloat)
  , (String
"ctoi", String -> PrimitiveFunc
charToInteger)
  , (String
"itoc", String -> PrimitiveFunc
integerToChar)
  ]

lazyPrimitives :: [(String, String -> LazyPrimitiveFunc)]
lazyPrimitives :: [(String, String -> LazyPrimitiveFunc)]
lazyPrimitives =
  [ (String
"isBool",       (WHNFData -> EvalM WHNFData) -> String -> LazyPrimitiveFunc
lazyOneArg WHNFData -> EvalM WHNFData
isBool)
  , (String
"isInteger",    (WHNFData -> EvalM WHNFData) -> String -> LazyPrimitiveFunc
lazyOneArg WHNFData -> EvalM WHNFData
isInteger)
  , (String
"isRational",   (WHNFData -> EvalM WHNFData) -> String -> LazyPrimitiveFunc
lazyOneArg WHNFData -> EvalM WHNFData
isRational)
  , (String
"isScalar",     (WHNFData -> EvalM WHNFData) -> String -> LazyPrimitiveFunc
lazyOneArg WHNFData -> EvalM WHNFData
isScalar)
  , (String
"isFloat",      (WHNFData -> EvalM WHNFData) -> String -> LazyPrimitiveFunc
lazyOneArg WHNFData -> EvalM WHNFData
isFloat)
  , (String
"isChar",       (WHNFData -> EvalM WHNFData) -> String -> LazyPrimitiveFunc
lazyOneArg WHNFData -> EvalM WHNFData
isChar)
  , (String
"isString",     (WHNFData -> EvalM WHNFData) -> String -> LazyPrimitiveFunc
lazyOneArg WHNFData -> EvalM WHNFData
isString)
  , (String
"isCollection", (WHNFData -> EvalM WHNFData) -> String -> LazyPrimitiveFunc
lazyOneArg WHNFData -> EvalM WHNFData
isCollection)
  , (String
"isHash",       (WHNFData -> EvalM WHNFData) -> String -> LazyPrimitiveFunc
lazyOneArg WHNFData -> EvalM WHNFData
isHash)
  , (String
"isTensor",     (WHNFData -> EvalM WHNFData) -> String -> LazyPrimitiveFunc
lazyOneArg WHNFData -> EvalM WHNFData
isTensor)
  ]

--
-- Typing
--

isBool :: WHNFData -> EvalM WHNFData
isBool :: WHNFData -> EvalM WHNFData
isBool (Value (Bool Bool
_)) = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isBool WHNFData
_                = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
False

isInteger :: WHNFData -> EvalM WHNFData
isInteger :: WHNFData -> EvalM WHNFData
isInteger (Value (ScalarData (Div (Plus []) (Plus [Term Integer
1 []]))))          = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isInteger (Value (ScalarData (Div (Plus [Term Integer
_ []]) (Plus [Term Integer
1 []])))) = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isInteger WHNFData
_                                                                = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
False

isRational :: WHNFData -> EvalM WHNFData
isRational :: WHNFData -> EvalM WHNFData
isRational (Value (ScalarData (Div (Plus []) (Plus [Term Integer
_ []]))))          = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isRational (Value (ScalarData (Div (Plus [Term Integer
_ []]) (Plus [Term Integer
_ []])))) = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isRational WHNFData
_                                                                = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
False

isScalar :: WHNFData -> EvalM WHNFData
isScalar :: WHNFData -> EvalM WHNFData
isScalar (Value (ScalarData ScalarData
_)) = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isScalar WHNFData
_                      = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
False

isTensor :: WHNFData -> EvalM WHNFData
isTensor :: WHNFData -> EvalM WHNFData
isTensor (Value (TensorData Tensor EgisonValue
_)) = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isTensor (ITensor Tensor ObjectRef
_)            = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isTensor WHNFData
_                      = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
False

isFloat :: WHNFData -> EvalM WHNFData
isFloat :: WHNFData -> EvalM WHNFData
isFloat (Value (Float Double
_)) = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isFloat WHNFData
_                 = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
False

isChar :: WHNFData -> EvalM WHNFData
isChar :: WHNFData -> EvalM WHNFData
isChar (Value (Char Char
_)) = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isChar WHNFData
_                = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
False

isString :: WHNFData -> EvalM WHNFData
isString :: WHNFData -> EvalM WHNFData
isString (Value (String Text
_)) = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isString WHNFData
_                  = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
False

isCollection :: WHNFData -> EvalM WHNFData
isCollection :: WHNFData -> EvalM WHNFData
isCollection (Value (Collection Seq EgisonValue
_)) = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isCollection (ICollection IORef (Seq Inner)
_)        = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isCollection WHNFData
_                      = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
False

isHash :: WHNFData -> EvalM WHNFData
isHash :: WHNFData -> EvalM WHNFData
isHash (Value (IntHash HashMap Integer EgisonValue
_))  = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isHash (Value (CharHash HashMap Char EgisonValue
_)) = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isHash (Value (StrHash HashMap Text EgisonValue
_))  = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isHash (IIntHash HashMap Integer ObjectRef
_)         = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isHash (ICharHash HashMap Char ObjectRef
_)        = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isHash (IStrHash HashMap Text ObjectRef
_)         = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
True
isHash WHNFData
_                    = WHNFData -> EvalM WHNFData
forall (m :: * -> *) a. Monad m => a -> m a
return (WHNFData -> EvalM WHNFData)
-> (EgisonValue -> WHNFData) -> EgisonValue -> EvalM WHNFData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EgisonValue -> WHNFData
Value (EgisonValue -> EvalM WHNFData) -> EgisonValue -> EvalM WHNFData
forall a b. (a -> b) -> a -> b
$ Bool -> EgisonValue
Bool Bool
False

--
-- Transform
--
integerToFloat :: String -> PrimitiveFunc
integerToFloat :: String -> PrimitiveFunc
integerToFloat = String -> PrimitiveFunc
rationalToFloat

rationalToFloat :: String -> PrimitiveFunc
rationalToFloat :: String -> PrimitiveFunc
rationalToFloat = (EgisonValue -> EvalM EgisonValue) -> String -> PrimitiveFunc
oneArg ((EgisonValue -> EvalM EgisonValue) -> String -> PrimitiveFunc)
-> (EgisonValue -> EvalM EgisonValue) -> String -> PrimitiveFunc
forall a b. (a -> b) -> a -> b
$ \EgisonValue
val ->
  case EgisonValue
val of
    ScalarData (Div (Plus []) PolyExpr
_)                           -> EgisonValue -> EvalM EgisonValue
forall (m :: * -> *) a. Monad m => a -> m a
return (EgisonValue -> EvalM EgisonValue)
-> EgisonValue -> EvalM EgisonValue
forall a b. (a -> b) -> a -> b
$ Double -> EgisonValue
Float Double
0
    ScalarData (Div (Plus [Term Integer
x []]) (Plus [Term Integer
y []])) -> EgisonValue -> EvalM EgisonValue
forall (m :: * -> *) a. Monad m => a -> m a
return (EgisonValue -> EvalM EgisonValue)
-> EgisonValue -> EvalM EgisonValue
forall a b. (a -> b) -> a -> b
$ Double -> EgisonValue
Float (Rational -> Double
forall a. Fractional a => Rational -> a
fromRational (Integer
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
y))
    EgisonValue
_                                                      -> (CallStack -> EgisonError) -> EvalM EgisonValue
forall a. (CallStack -> EgisonError) -> EvalM a
throwErrorWithTrace (String -> WHNFData -> CallStack -> EgisonError
TypeMismatch String
"integer or rational number" (EgisonValue -> WHNFData
Value EgisonValue
val))

charToInteger :: String -> PrimitiveFunc
charToInteger :: String -> PrimitiveFunc
charToInteger = (Char -> Integer) -> String -> PrimitiveFunc
forall a b.
(EgisonData a, EgisonData b) =>
(a -> b) -> String -> PrimitiveFunc
unaryOp Char -> Integer
ctoi
  where
    ctoi :: Char -> Integer
    ctoi :: Char -> Integer
ctoi = Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Integer) -> (Char -> Int) -> Char -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord

integerToChar :: String -> PrimitiveFunc
integerToChar :: String -> PrimitiveFunc
integerToChar = (Integer -> Char) -> String -> PrimitiveFunc
forall a b.
(EgisonData a, EgisonData b) =>
(a -> b) -> String -> PrimitiveFunc
unaryOp Integer -> Char
itoc
  where
    itoc :: Integer -> Char
    itoc :: Integer -> Char
itoc = Int -> Char
chr (Int -> Char) -> (Integer -> Int) -> Integer -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral