module System.Environment where

open import Level
open import Agda.Builtin.String
open import Agda.Builtin.Unit
open import Foreign.Haskell.Coerce
open import System.FilePath.Posix

open import Data.Maybe.Base
open import Data.Product
open import Agda.Builtin.List
import System.Environment.Primitive as Prim

open import Codata.IO

private
  variable
    a  : Level

getArgs           : IO  (List String)
getProgName       : IO  String
getExecutablePath : IO  AbsolutePath
lookupEnv         : String  IO  (Maybe String)
setEnv            : String  String  IO  
unsetEnv          : String  IO  
withArgs          : {A : Set a} {{_ : a ≤ˡ }}  List String  IO  A  IO  A
withProgName      : {A : Set a} {{_ : a ≤ˡ }}  String  IO  A  IO  A
getEnvironment    : IO  (List (String × String))

getArgs           = lift Prim.getArgs
getProgName       = lift Prim.getProgName
getExecutablePath = lift Prim.getExecutablePath
lookupEnv         = λ var  coerce <$> lift (Prim.lookupEnv var)
setEnv            = λ var str  lift (Prim.setEnv var str)
unsetEnv          = λ var  lift (Prim.unsetEnv var)
withArgs          = λ args io  lift (Prim.withArgs args (run io))
withProgName      = λ nm io  lift (Prim.withProgName nm (run io))
getEnvironment    = lift (coerce Prim.getEnvironment)