| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Exiting the program. |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --guardedness #-} |
| 8 |
|
| 9 |
module System.Exit where |
| 10 |
|
| 11 |
open import Level using (Level) |
| 12 |
open import Data.Bool.Base using (Bool; true; false; not) |
| 13 |
open import Data.Integer.Base using (ℤ; +_) |
| 14 |
open import Data.String.Base using (String) |
| 15 |
open import Function.Base using (_$_; _∘′_) |
| 16 |
open import IO using (IO; lift; _>>_; putStrLn) |
| 17 |
|
| 18 |
------------------------------------------------------------------------ |
| 19 |
-- Re-exporting the ExitCode data structure |
| 20 |
|
| 21 |
open import System.Exit.Primitive as Prim |
| 22 |
public |
| 23 |
using ( ExitCode |
| 24 |
; ExitSuccess |
| 25 |
; ExitFailure |
| 26 |
) |
| 27 |
|
| 28 |
------------------------------------------------------------------------ |
| 29 |
-- Tests |
| 30 |
|
| 31 |
isSuccess : ExitCode → Bool |
| 32 |
isSuccess ExitSuccess = true |
| 33 |
isSuccess (ExitFailure _) = false |
| 34 |
|
| 35 |
isFailure : ExitCode → Bool |
| 36 |
isFailure = not ∘′ isSuccess |
| 37 |
|
| 38 |
------------------------------------------------------------------------ |
| 39 |
-- Various exiting function |
| 40 |
|
| 41 |
private |
| 42 |
variable |
| 43 |
a : Level |
| 44 |
A : Set a |
| 45 |
|
| 46 |
exitWith : ExitCode → IO A |
| 47 |
exitWith c = lift (Prim.exitWith c) |
| 48 |
|
| 49 |
exitFailure : IO A |
| 50 |
exitFailure = exitWith (ExitFailure (+ 1)) |
| 51 |
|
| 52 |
exitSuccess : IO A |
| 53 |
exitSuccess = exitWith ExitSuccess |
| 54 |
|
| 55 |
die : String → IO A |
| 56 |
die str = do |
| 57 |
putStrLn str |
| 58 |
exitFailure |