Last active
February 25, 2021 23:25
Star
You must be signed in to star a gist
Cachix Server Repl using hint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS_GHC -fno-warn-orphans #-} | |
module Repl where | |
import Cachix.Config (readConfig) | |
import Cachix.Env (setupApp) | |
import Cachix.Server.Prelude | |
import qualified Control.Exception.Safe as Safe | |
import qualified Language.Haskell.Interpreter as Interpreter | |
import Protolude | |
import qualified System.IO | |
import qualified Prelude | |
extensions :: Interpreter.OptionVal (Interpreter.InterpreterT App) | |
extensions = | |
Interpreter.languageExtensions | |
Interpreter.:= [ Interpreter.NoImplicitPrelude, | |
Interpreter.DeriveGeneric, | |
Interpreter.LambdaCase, | |
Interpreter.OverloadedStrings | |
] | |
main :: FilePath -> IO () | |
main configPath = do | |
config <- readConfig $ toS configPath | |
finished <- setupApp config $ Interpreter.runInterpreter $ do | |
Interpreter.set | |
[ extensions, | |
Interpreter.searchPath Interpreter.:= ["src"], | |
Interpreter.installedModulesInScope Interpreter.:= True | |
] | |
putText "Loading modules ..." | |
Interpreter.loadModules ["Cachix.Server"] | |
Interpreter.setImports ["Prelude"] | |
putText "" | |
putText "Welcome to Cachix Server REPL!" | |
putText "" | |
loop | |
escalate finished | |
loop :: Interpreter.InterpreterT App () | |
loop = do | |
liftIO $ putStr ("> " :: Text) | |
liftIO $ System.IO.hFlush System.IO.stdout | |
statement <- liftIO Prelude.getLine | |
type_ <- Interpreter.typeOf statement | |
Safe.handle handleInterpreterError $ Interpreter.runStmt statement | |
liftIO $ putStrLn $ ":: " <> type_ | |
loop | |
handleInterpreterError :: Interpreter.InterpreterError -> Interpreter.InterpreterT App () | |
handleInterpreterError = print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment