| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Primitive System.Environment: simple bindings to Haskell functions |
| 5 |
-- |
| 6 |
-- Note that we currently leave out: |
| 7 |
-- * filepath-related functions (until we have a good representation of |
| 8 |
-- absolute vs. relative & directory vs. file) |
| 9 |
-- * functions that may fail with an exception |
| 10 |
-- e.g. we provide `lookupEnv` but not `getEnv` |
| 11 |
------------------------------------------------------------------------ |
| 12 |
|
| 13 |
{-# OPTIONS --cubical-compatible #-} |
| 14 |
|
| 15 |
module System.Environment.Primitive where |
| 16 |
|
| 17 |
open import IO.Primitive.Core using (IO) |
| 18 |
open import Data.List.Base using (List) |
| 19 |
open import Data.Maybe.Base using (Maybe) |
| 20 |
open import Data.String.Base using (String) |
| 21 |
open import Data.Unit.Base using (⊤) |
| 22 |
|
| 23 |
open import Foreign.Haskell.Pair using (Pair) |
| 24 |
|
| 25 |
{-# FOREIGN GHC import qualified System.Environment as SE #-} |
| 26 |
{-# FOREIGN GHC import qualified Data.Text as T #-} |
| 27 |
{-# FOREIGN GHC import Data.Bifunctor (bimap) #-} |
| 28 |
{-# FOREIGN GHC import Data.Function (on) #-} |
| 29 |
|
| 30 |
postulate |
| 31 |
getArgs : IO (List String) |
| 32 |
getProgName : IO String |
| 33 |
lookupEnv : String → IO (Maybe String) |
| 34 |
setEnv : String → String → IO ⊤ |
| 35 |
unsetEnv : String → IO ⊤ |
| 36 |
withArgs : ∀ {a} {A : Set a} → List String → IO A → IO A |
| 37 |
withProgName : ∀ {a} {A : Set a} → String → IO A → IO A |
| 38 |
getEnvironment : IO (List (Pair String String)) |
| 39 |
|
| 40 |
{-# COMPILE GHC getArgs = fmap (fmap T.pack) SE.getArgs #-} |
| 41 |
{-# COMPILE GHC getProgName = fmap T.pack SE.getProgName #-} |
| 42 |
{-# COMPILE GHC lookupEnv = fmap (fmap T.pack) . SE.lookupEnv . T.unpack #-} |
| 43 |
{-# COMPILE GHC setEnv = SE.setEnv `on` T.unpack #-} |
| 44 |
{-# COMPILE GHC unsetEnv = SE.unsetEnv . T.unpack #-} |
| 45 |
{-# COMPILE GHC withArgs = \ _ _ -> SE.withArgs . fmap T.unpack #-} |
| 46 |
{-# COMPILE GHC withProgName = \ _ _ -> SE.withProgName . T.unpack #-} |
| 47 |
{-# COMPILE GHC getEnvironment = fmap (fmap (bimap T.pack T.pack)) SE.getEnvironment #-} |