Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ base ] Add casts between Int and ExitCode #3432

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions libs/base/System.idr
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,20 @@ data ExitCode : Type where
||| @prf Proof that the int value is non-zero.
ExitFailure : (errNo : Int) -> (So (not $ errNo == 0)) => ExitCode

export
Cast Int ExitCode where
cast 0 = ExitSuccess
cast code = ExitFailure code @{believe_me Oh}

export
Cast ExitCode Int where
cast ExitSuccess = 0
cast (ExitFailure code) = code

||| Exit the program normally, with the specified status.
export
exitWith : HasIO io => ExitCode -> io a
exitWith ExitSuccess = primIO $ believe_me $ prim__exit 0
exitWith (ExitFailure code) = primIO $ believe_me $ prim__exit code
exitWith = primIO . believe_me . prim__exit . cast

||| Exit the program with status value 1, indicating failure.
||| If you want to specify a custom status value, see `exitWith`.
Expand Down
Loading