Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add getEnvironment
Fixes #6165
  • Loading branch information
japgolly committed Feb 7, 2026
commit a0cb94a4094430d9de99d3ca207478434500c9d8
1 change: 1 addition & 0 deletions parser-typechecker/src/Unison/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ ioBuiltins =
("IO.seekHandle.impl.v3", handle --> smode --> int --> iof unit),
("IO.handlePosition.impl.v3", handle --> iof nat),
("IO.getEnv.impl.v1", text --> iof text),
("IO.getEnvironment.impl.v1", unit --> iof (list (tuple [text, text]))),
("IO.getArgs.impl.v1", unit --> iof (list text)),
("IO.getBuffering.impl.v3", handle --> iof bmode),
("IO.setBuffering.impl.v3", handle --> bmode --> iof unit),
Expand Down
2 changes: 2 additions & 0 deletions unison-runtime/src/Unison/Runtime/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,8 @@ declareForeigns = do

declareForeign Tracked 1 IO_getEnv_impl_v1

declareForeign Tracked 0 IO_getEnvironment_impl_v1

declareForeign Tracked 0 IO_getArgs_impl_v1

declareForeign Tracked 1 IO_isDirectory_impl_v3
Expand Down
3 changes: 3 additions & 0 deletions unison-runtime/src/Unison/Runtime/Foreign/Function.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ import System.Directory as SYS
import System.Environment as SYS
( getArgs,
getEnv,
getEnvironment,
)
import System.Exit as SYS (ExitCode (..))
import System.FilePath (isPathSeparator)
Expand Down Expand Up @@ -335,6 +336,8 @@ foreignCallHelper = \case
IO_setCurrentDirectory_impl_v3 -> mkForeignIOF setCurrentDirectory
IO_fileExists_impl_v3 -> mkForeignIOF doesPathExist
IO_getEnv_impl_v1 -> mkForeignIOF getEnv
IO_getEnvironment_impl_v1 -> mkForeignIOF $
\() -> getEnvironment
IO_getArgs_impl_v1 -> mkForeignIOF $
\() -> fmap Util.Text.pack <$> SYS.getArgs
IO_isDirectory_impl_v3 -> mkForeignIOF doesDirectoryExist
Expand Down
2 changes: 2 additions & 0 deletions unison-runtime/src/Unison/Runtime/Foreign/Function/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ data ForeignFunc
| IO_setCurrentDirectory_impl_v3
| IO_fileExists_impl_v3
| IO_getEnv_impl_v1
| IO_getEnvironment_impl_v1
| IO_getArgs_impl_v1
| IO_isDirectory_impl_v3
| IO_createDirectory_impl_v3
Expand Down Expand Up @@ -501,6 +502,7 @@ foreignFuncBuiltinName = \case
IO_setCurrentDirectory_impl_v3 -> "IO.setCurrentDirectory.impl.v3"
IO_fileExists_impl_v3 -> "IO.fileExists.impl.v3"
IO_getEnv_impl_v1 -> "IO.getEnv.impl.v1"
IO_getEnvironment_impl_v1 -> "IO.getEnvironment.impl.v1"
IO_getArgs_impl_v1 -> "IO.getArgs.impl.v1"
IO_isDirectory_impl_v3 -> "IO.isDirectory.impl.v3"
IO_createDirectory_impl_v3 -> "IO.createDirectory.impl.v3"
Expand Down
4 changes: 4 additions & 0 deletions unison-src/transcripts-using-base/all-base-hashes.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -4275,4 +4275,8 @@ This transcript is intended to make visible accidental changes to the hashing al
1185. -- #lcmj2envm11lrflvvcl290lplhvbccv82utoej0lg0eomhmsf2vrv8af17k6if7ff98fp1b13rkseng3fng4stlr495c8dn3gn4k400
|> : a -> (a ->{g} t) ->{g} t

1186. -- ##IO.getEnvironment.impl.v1
builtin.io2.IO.getEnvironment.impl : '{IO} Either
Failure [(Text, Text)]

```
14 changes: 14 additions & 0 deletions unison-src/transcripts/pretty-print-libraries.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -57108,6 +57108,9 @@ IO.doc =
arguments.

`` getEnv var `` gets the value of the environment variable named `var`.

`` getEnvironment `` gets the list of all environment variables and
their values.

# System clocks

Expand Down Expand Up @@ -57807,6 +57810,17 @@ IO.getEnv.doc =

-- builtin IO.getEnv.impl : Text ->{IO} Either Failure Text

IO.getEnvironment : '{IO, Exception} [(Text, Text)]
IO.getEnvironment _ = Either.toException getEnvironment.impl()

IO.getEnvironment.doc : Doc
IO.getEnvironment.doc =
{{
Get a list of all environment variables and their values.
}}

-- builtin IO.getEnvironment.impl : '{IO} Either Failure [(Text, Text)]

IO.Handle.BufferMode.doc : Doc
IO.Handle.BufferMode.doc =
{{
Expand Down