jl-0.1.0: src/JL.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
-- | Main library entry point.
module JL where
import Data.Aeson
import Data.ByteString.Lazy (ByteString)
import qualified Data.Map.Strict as M
import Data.Text (Text)
import qualified Data.Text.IO as T
import JL.Functions
import JL.Inferer
import JL.Interpreter
import JL.Parser
import JL.Printer
import JL.Serializer
import JL.Types
repl :: Text -> ByteString -> IO ()
repl inp js =
case decode js of
Nothing -> error "Invalid JSON"
Just j ->
case parseText "" inp of
Left err -> error (show err)
Right expr0 -> do
T.putStrLn
(prettyExp expr <> " : " <>
prettyType (infer context expr (map TypeVariable [1 ..])))
T.putStrLn
(prettyCore
(eval (foldl (\e (v, f) -> subst v f e) (desugar expr) (M.toList scope))))
where expr = ApplicationExpression expr0 (valueToExpression j)