APIProcess
Process
The running program’s arguments, environment variables, and exit status.
The prelude does not expose it; import Process.
Arguments and variables are the Environment effect: code that reads them
performs it, and the program chooses where they come from by running that
code under runSystem, for the real process, or runWith, for fixed
values. runSystem is its default handler, so main can read them
directly.
A program ends normally by returning from main: () is status 0, and a
Status is that status, applied after every scope has been released and
every task has finished. exit is the drastic alternative that ends the
process at once.
Status
type StatusSource
A process exit status, from 0 through 255.
Instances:
Eq Status
Environment
effect EnvironmentSource
Reading the environment the program was started with: its command-line
arguments and environment variables. A main that performs it runs under
runSystem unless it installs another runner.
Operations
args
args : () ->{Environment} List StringSource
The arguments, without the program name. fango run passes every
argument after the source file.
env
env : String ->{Environment} Maybe StringSource
The value of the variable with this name, or Nothing when it is not
set. A variable set to the empty string is Just "".
exit
exit : Status ->{IO} aSource
Ends the process at once with the status, from any task. It runs no Fango
cleanup: no bracket or finally release, no buffered Writer flush, no
task cancellation or draining. Earlier console output is kept. In the
interpreter or the REPL it ends the program without ending the session.
To finish normally, return the status from main instead.
failure
failure : StatusSource
Status 1.
runSystem
runSystem : (() ->{Environment, e} a) ->{IO, e} aSource
Answers every operation from the real process.
runWith
runWith : List String -> Dict String String -> (() ->{Environment, e} a) ->{e} aSource
Answers every operation from fixed arguments and variables, so code that reads them can run without a real process.
import Dict
import List
import Maybe exposing (Maybe(..))
import Process
home = Dict.fromList [("HOME", "/home/me")]
Process.runWith ["a", "b"] home { List.length (Process.args ()) } == 2
Process.runWith [] home { Process.env "HOME" } == Just "/home/me"
Process.runWith [] home { Process.env "PATH" } == Nothing
Process.runWith [] home { Dict.size (Process.variables ()) } == 1
status
status : Int -> StatusSource
The status with this number. A number outside 0 through 255 is a runtime fault, like a division by zero, so a requested failure can never wrap around to success.
import Process
Process.status 0 == Process.success
Process.status 1 == Process.failure
success
success : StatusSource
Status 0, which a main returning () also ends with.
