dhall-1.0.1: A configuration language guaranteed to terminate

Safe HaskellNone
LanguageHaskell98

Dhall.Import

Contents

Description

Dhall lets you import external expressions located either in local files or hosted on network endpoints.

To import a local file as an expression, just insert the path to the file, prepending a ./ if the path is relative to the current directory. For example, if you create a file named id with the following contents:

$ cat id
λ(a : Type) → λ(x : a) → x

Then you can use the file directly within a dhall program just by referencing the file's path:

$ dhall
./id Bool True
<Ctrl-D>
Bool

True

Imported expressions may contain imports of their own, too, which will continue to be resolved. However, Dhall will prevent cyclic imports. For example, if you had these two files:

$ cat foo
./bar
$ cat bar
./foo

... Dhall would throw the following exception if you tried to import foo:

$ dhall
./foo
^D
↳ ./foo 
  ↳ ./bar 

Cyclic import: ./foo 

You can also import expressions hosted on network endpoints. Just use the URL

http://host[:port]/path

The compiler expects the downloaded expressions to be in the same format as local files, specifically UTF8-encoded source code text.

For example, if our id expression were hosted at http://example.com/id, then we would embed the expression within our code using:

http://example.com/id

You can also reuse directory names as expressions. If you provide a path to a local or remote directory then the compiler will look for a file named @ within that directory and use that file to represent the directory.

Synopsis

Import

exprFromFile :: FilePath -> IO (Expr Src Path) Source

Parse an expression from a FilePath containing a Dhall program

exprFromURL :: Manager -> Text -> IO (Expr Src Path) Source

Parse an expression from a URL hosting a Dhall program

load :: Expr Src Path -> IO (Expr Src X) Source

Resolve all imports within an expression

newtype Cycle Source

An import failed because of a cycle in the import graph

Constructors

Cycle 

Fields

cyclicImport :: Path

The offending cyclic import

newtype ReferentiallyOpaque Source

Dhall tries to ensure that all expressions hosted on network endpoints are weakly referentially transparent, meaning roughly that any two clients will compile the exact same result given the same URL.

To be precise, a strong interpretaton of referential transparency means that if you compiled a URL you could replace the expression hosted at that URL with the compiled result. Let's term this "static linking". Dhall (very intentionally) does not satisfy this stronger interpretation of referential transparency since "statically linking" an expression (i.e. permanently resolving all imports) means that the expression will no longer update if its dependencies change.

In general, either interpretation of referential transparency is not enforceable in a networked context since one can easily violate referential transparency with a custom DNS, but Dhall can still try to guard against common unintentional violations. To do this, Dhall enforces that a non-local import may not reference a local import.

Local imports are defined as:

  • A file
  • A URL with a host of localhost or 127.0.0.1

All other imports are defined to be non-local

Constructors

ReferentiallyOpaque 

Fields

opaqueImport :: Path

The offending opaque import

data Imported e Source

Extend another exception with the current import stack

Constructors

Imported 

Fields

importStack :: [Path]

Imports resolved so far, in reverse order

nested :: e

The nested exception

Instances

data MissingFile Source

Exception thrown when an imported file is missing

Constructors

MissingFile