Module REPL.Main

A universal REPL which can be used on top of a Curry compiler

Author: Michael Hanus

Version: March 2023

Summary of exported operations:

mainREPL :: CCDescription -> IO ()  Non-deterministic 
The main operation to start the REPL.
processArgsAndStart :: ReplState -> [String] -> IO ()  Non-deterministic 
isCommand :: String -> Bool  Deterministic 
May a String be a REPL command?
printHelp :: ReplState -> IO ()  Deterministic 
repLoop :: ReplState -> IO ()  Non-deterministic 
mGetLine :: IO (Maybe String)  Deterministic 
calcPrompt :: ReplState -> String  Deterministic 
substS :: String -> String -> String  Deterministic 
cleanUpAndExitRepl :: ReplState -> IO ()  Deterministic 
processInput :: ReplState -> String -> IO ()  Non-deterministic 
evalExpression :: ReplState -> String -> IO ReplState  Non-deterministic 
Evaluate an expression w.r.t.
importUnsafeModule :: ReplState -> IO Bool  Non-deterministic 
currentFrontendParams :: ReplState -> Bool -> FrontendParams  Deterministic 
compilerOutDir :: ReplState -> String  Deterministic 
acyFileName :: ReplState -> String -> String  Deterministic 
verbCallFrontendWithParams :: ReplState -> FrontendTarget -> FrontendParams -> String -> IO ()  Non-deterministic 
writeSimpleMainExpFile :: ReplState -> String -> IO ()  Deterministic 
writeMainExpFile :: ReplState -> [String] -> Maybe String -> String -> IO ()  Deterministic 
getAcyOfMainExpMod :: ReplState -> IO (Maybe CurryProg)  Non-deterministic 
getAcyOfExpr :: ReplState -> String -> IO (Maybe CurryProg)  Non-deterministic 
printTypeOfExp :: ReplState -> String -> IO Bool  Non-deterministic 
getModuleOfFunction :: ReplState -> String -> IO String  Non-deterministic 
processCommand :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
unsafeExec :: ReplState -> IO (Maybe ReplState) -> IO (Maybe ReplState)  Deterministic 
replCommands :: [(String,ReplState -> String -> IO (Maybe ReplState))]  Non-deterministic 
skipCommand :: String -> IO (Maybe ReplState)  Deterministic 
Skip an erroneous command with an error message
processSysCall :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Execute a call to a system command
processAdd :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :add command
processBrowse :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :browse command
processCd :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :cd command
processCompile :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :compile command
processEdit :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :edit command
processEval :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
Process :eval command
processFork :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
Process :fork command
processHelp :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :help command
processInterface :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :interface command
processLoad :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
Process :load command
processReload :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
Process :reload command
processModules :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :modules command
processPrograms :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :programs command
processQuit :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :quit command
processSave :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
processShow :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :show command
processSource :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
Process :source command
processType :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
Process :type command
processUsedImports :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
Process :usedimports command
printHelpOnCommands :: IO ()  Deterministic 
printAllLoadedModules :: ReplState -> IO ()  Deterministic 
Print all Curry programs in current load path.
printAllLoadPathPrograms :: ReplState -> IO ()  Deterministic 
Print all Curry programs in current load path.
processSetOption :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
replOptions :: ReplState -> [(String,ReplState -> String -> IO (Maybe ReplState))]  Non-deterministic 
setPrompt :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
setTimeout :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
printOptions :: ReplState -> IO ()  Deterministic 
showCurrentOptions :: ReplState -> String  Deterministic 
formatVarVals :: String -> [(String,String)] -> [String]  Deterministic 
defaultImportPaths :: ReplState -> IO [String]  Deterministic 
The default import paths of the Curry compiler.
defaultImportPathsWith :: ReplState -> String -> IO [String]  Deterministic 
setOptionPath :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
compileMainExpression :: ReplState -> String -> Bool -> IO Int  Non-deterministic 
execAndRemove :: ReplState -> String -> String -> IO Int  Deterministic 
cleanModule :: ReplState -> String -> IO ()  Deterministic 
unlessKeepFiles :: ReplState -> IO () -> IO ()  Deterministic 
keepFiles :: ReplState -> Bool  Deterministic 
insertFreeVarsShowInMainExp :: ReplState -> CurryProg -> String -> IO (Maybe (CurryProg,String,[String]))  Non-deterministic 
breakWhereFreeClause :: String -> (String,String)  Deterministic 
makeMainExpMonomorphic :: ReplState -> CurryProg -> String -> IO (Maybe (CurryProg,String))  Non-deterministic 
If the main expression is polymorphic, make it monomorphic by adding a type declaration where type variables are replaced by type ().
defaultQualTypeExpr :: CQualTypeExpr -> CQualTypeExpr  Non-deterministic 
substTypeVar :: (Int,String) -> CTypeExpr -> CTypeExpr -> CTypeExpr  Deterministic 
parseCurryProgram :: ReplState -> String -> Bool -> IO (Maybe ReplState)  Non-deterministic 
loadCurryProgram :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 
compileCurryProgram :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 
curryCompilerCommand :: ReplState -> [String] -> String  Deterministic 
getModuleName :: ReplState -> String -> IO String  Deterministic 
Extract a module name, possibly prefixed by a path, from an argument, or return the current module name if the argument is the empty string.
reduceVerbose :: ReplState -> ReplState  Deterministic 
showFunctionInModule :: ReplState -> String -> String -> IO (Maybe ReplState)  Deterministic 
checkAndCallCpmTool :: String -> String -> (String -> IO (Maybe ReplState)) -> IO (Maybe ReplState)  Deterministic 
execCommandWithPath :: ReplState -> String -> [String] -> IO (Maybe ReplState)  Deterministic 
checkForCommand :: String -> String -> IO (Maybe ReplState) -> IO (Maybe ReplState)  Deterministic 
checkForWish :: IO (Maybe ReplState) -> IO (Maybe ReplState)  Deterministic 
terminateSourceProgGUIs :: ReplState -> IO ReplState  Deterministic 

Exported operations:

mainREPL :: CCDescription -> IO ()  Non-deterministic 

The main operation to start the REPL. It is parameterized over a description of a Curry compiler.

processArgsAndStart :: ReplState -> [String] -> IO ()  Non-deterministic 

isCommand :: String -> Bool  Deterministic 

May a String be a REPL command?

printHelp :: ReplState -> IO ()  Deterministic 

repLoop :: ReplState -> IO ()  Non-deterministic 

mGetLine :: IO (Maybe String)  Deterministic 

calcPrompt :: ReplState -> String  Deterministic 

substS :: String -> String -> String  Deterministic 

cleanUpAndExitRepl :: ReplState -> IO ()  Deterministic 

processInput :: ReplState -> String -> IO ()  Non-deterministic 

evalExpression :: ReplState -> String -> IO ReplState  Non-deterministic 

Evaluate an expression w.r.t. currently loaded modules

importUnsafeModule :: ReplState -> IO Bool  Non-deterministic 

compilerOutDir :: ReplState -> String  Deterministic 

acyFileName :: ReplState -> String -> String  Deterministic 

writeSimpleMainExpFile :: ReplState -> String -> IO ()  Deterministic 

writeMainExpFile :: ReplState -> [String] -> Maybe String -> String -> IO ()  Deterministic 

getAcyOfMainExpMod :: ReplState -> IO (Maybe CurryProg)  Non-deterministic 

getAcyOfExpr :: ReplState -> String -> IO (Maybe CurryProg)  Non-deterministic 

printTypeOfExp :: ReplState -> String -> IO Bool  Non-deterministic 

getModuleOfFunction :: ReplState -> String -> IO String  Non-deterministic 

processCommand :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

unsafeExec :: ReplState -> IO (Maybe ReplState) -> IO (Maybe ReplState)  Deterministic 

replCommands :: [(String,ReplState -> String -> IO (Maybe ReplState))]  Non-deterministic 

skipCommand :: String -> IO (Maybe ReplState)  Deterministic 

Skip an erroneous command with an error message

processSysCall :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Execute a call to a system command

processAdd :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :add command

processBrowse :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :browse command

processCd :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :cd command

processCompile :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :compile command

processEdit :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :edit command

processEval :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

Process :eval command

processFork :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

Process :fork command

processHelp :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :help command

processInterface :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :interface command

processLoad :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

Process :load command

processReload :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

Process :reload command

processModules :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :modules command

processPrograms :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :programs command

processQuit :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :quit command

processSave :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

processShow :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :show command

processSource :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

Process :source command

processType :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

Process :type command

processUsedImports :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

Process :usedimports command

printHelpOnCommands :: IO ()  Deterministic 

printAllLoadedModules :: ReplState -> IO ()  Deterministic 

Print all Curry programs in current load path. Programs found in subdirectories are assumed to be hierarchical. To avoid loops in cyclic directory structure, we put a depth limit on the recursive search.

printAllLoadPathPrograms :: ReplState -> IO ()  Deterministic 

Print all Curry programs in current load path. Programs found in subdirectories are assumed to be hierarchical. To avoid loops in cyclic directory structure, we put a depth limit on the recursive search.

processSetOption :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

replOptions :: ReplState -> [(String,ReplState -> String -> IO (Maybe ReplState))]  Non-deterministic 

setPrompt :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

setTimeout :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

printOptions :: ReplState -> IO ()  Deterministic 

showCurrentOptions :: ReplState -> String  Deterministic 

formatVarVals :: String -> [(String,String)] -> [String]  Deterministic 

defaultImportPaths :: ReplState -> IO [String]  Deterministic 

The default import paths of the Curry compiler. It consists of the path defined by the environment variable CURRYPATH, and the "libraries" property defined in ~/.compilerrc

defaultImportPathsWith :: ReplState -> String -> IO [String]  Deterministic 

setOptionPath :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

compileMainExpression :: ReplState -> String -> Bool -> IO Int  Non-deterministic 

execAndRemove :: ReplState -> String -> String -> IO Int  Deterministic 

cleanModule :: ReplState -> String -> IO ()  Deterministic 

unlessKeepFiles :: ReplState -> IO () -> IO ()  Deterministic 

keepFiles :: ReplState -> Bool  Deterministic 

insertFreeVarsShowInMainExp :: ReplState -> CurryProg -> String -> IO (Maybe (CurryProg,String,[String]))  Non-deterministic 

breakWhereFreeClause :: String -> (String,String)  Deterministic 

makeMainExpMonomorphic :: ReplState -> CurryProg -> String -> IO (Maybe (CurryProg,String))  Non-deterministic 

If the main expression is polymorphic, make it monomorphic by adding a type declaration where type variables are replaced by type (). Before, type variables with a numeric constraint like Num/Integral or Fractional/Floating are defaulted to the types Int or Float, respectively. The type of the main expression is only allowed to contain numeric constraints. If the main exp has type IO t where t is monomorphic and not a function, t /= (), and withShow is True, then >>= print is added to the expression to print the computed value. Otherwise (if the main exp has type IO t), >>= return is added in order to support raising non-determinism errors during the monadic bind operation. The arguments are the AbstractCurry program of the main expression and the main expression as a string. The result is Nothing (if some error occurred) or the transformed AbstractCurry program and expression.

substTypeVar :: (Int,String) -> CTypeExpr -> CTypeExpr -> CTypeExpr  Deterministic 

parseCurryProgram :: ReplState -> String -> Bool -> IO (Maybe ReplState)  Non-deterministic 

loadCurryProgram :: ReplState -> String -> IO (Maybe ReplState)  Non-deterministic 

compileCurryProgram :: ReplState -> String -> IO (Maybe ReplState)  Deterministic 

curryCompilerCommand :: ReplState -> [String] -> String  Deterministic 

getModuleName :: ReplState -> String -> IO String  Deterministic 

Extract a module name, possibly prefixed by a path, from an argument, or return the current module name if the argument is the empty string.

showFunctionInModule :: ReplState -> String -> String -> IO (Maybe ReplState)  Deterministic 

checkAndCallCpmTool :: String -> String -> (String -> IO (Maybe ReplState)) -> IO (Maybe ReplState)  Deterministic 

execCommandWithPath :: ReplState -> String -> [String] -> IO (Maybe ReplState)  Deterministic 

checkForCommand :: String -> String -> IO (Maybe ReplState) -> IO (Maybe ReplState)  Deterministic 

checkForWish :: IO (Maybe ReplState) -> IO (Maybe ReplState)  Deterministic