Skip to content

Commit c274f8d

Browse files
authored
[ new ] bindings for Haskell's System.Exit (#1367)
1 parent 6b55dc5 commit c274f8d

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ New modules
213213
System.Environment.Primitive
214214
```
215215

216+
* Added bindings for Haskell's `System.Exit`:
217+
```
218+
System.Exit
219+
System.Exit.Primitive
220+
```
221+
216222
* New morphisms
217223
```
218224
Algebra.Morphism.LatticeMonomorphism

GenerateEverything.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ unsafeModules = map modToFile
4343
, "Relation.Binary.PropositionalEquality.TrustMe"
4444
, "System.Environment"
4545
, "System.Environment.Primitive"
46+
, "System.Exit"
47+
, "System.Exit.Primitive"
4648
, "Text.Pretty.Core"
4749
, "Text.Pretty"
4850
]

src/System/Exit.agda

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Exiting the program.
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K #-}
8+
9+
module System.Exit where
10+
11+
open import Level using (Level)
12+
open import Data.Nat.Base using (ℕ)
13+
open import Data.String.Base using (String)
14+
open import Function.Base using (_$_)
15+
open import IO using (IO; lift; _>>_; putStrLn)
16+
17+
------------------------------------------------------------------------
18+
-- Re-exporting the ExitCode data structure
19+
20+
open import System.Exit.Primitive as Prim
21+
using ( ExitCode
22+
; ExitSuccess
23+
; ExitFailure
24+
)
25+
public
26+
27+
------------------------------------------------------------------------
28+
-- Various exiting function
29+
30+
private
31+
variable
32+
a : Level
33+
A : Set a
34+
35+
exitWith : ExitCode IO A
36+
exitWith c = lift (Prim.exitWith c)
37+
38+
exitFailure : IO A
39+
exitFailure = exitWith (ExitFailure 1)
40+
41+
exitSuccess : IO A
42+
exitSuccess = exitWith ExitSuccess
43+
44+
die : String IO A
45+
die str = do
46+
putStrLn str
47+
exitFailure

src/System/Exit/Primitive.agda

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Primitive System.Exit simple bindings to Haskell functions
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K #-}
8+
9+
module System.Exit.Primitive where
10+
11+
open import Data.Nat.Base using (ℕ)
12+
open import IO.Primitive using (IO)
13+
14+
data ExitCode : Set where
15+
ExitSuccess : ExitCode
16+
ExitFailure : ExitCode
17+
18+
{-# FOREIGN GHC data AgdaExitCode = AgdaExitSuccess | AgdaExitFailure Integer #-}
19+
{-# COMPILE GHC ExitCode = data AgdaExitCode (AgdaExitSuccess | AgdaExitFailure) #-}
20+
21+
{-# FOREIGN GHC import qualified System.Exit as SE #-}
22+
23+
{-# FOREIGN GHC
24+
toExitCode :: AgdaExitCode -> SE.ExitCode
25+
toExitCode AgdaExitSuccess = SE.ExitSuccess
26+
toExitCode (AgdaExitFailure n) = SE.ExitFailure (fromIntegral n)
27+
#-}
28+
29+
postulate
30+
exitWith : {a} {A : Set a} ExitCode IO A
31+
32+
{-# COMPILE GHC exitWith = \ _ _ -> SE.exitWith . toExitCode #-}

0 commit comments

Comments
 (0)