diff --git a/dhall/Prelude/Bool/and b/dhall/Prelude/Bool/and new file mode 100644 index 0000000..6ad16a5 --- /dev/null +++ b/dhall/Prelude/Bool/and @@ -0,0 +1,3 @@ + missing + sha256:0b2114fa33cd76652e4360f012bc082718944fe4c5b28c975483178f8d9b0a6d +? ./and.dhall diff --git a/dhall/Prelude/Bool/and.dhall b/dhall/Prelude/Bool/and.dhall new file mode 100644 index 0000000..6b4e35c --- /dev/null +++ b/dhall/Prelude/Bool/and.dhall @@ -0,0 +1,14 @@ +{-| +The `and` function returns `False` if there are any `False` elements in the +`List` and returns `True` otherwise +-} +let and + : List Bool → Bool + = λ(xs : List Bool) → + List/fold Bool xs Bool (λ(l : Bool) → λ(r : Bool) → l && r) True + +let example0 = assert : and [ True, False, True ] ≡ False + +let example1 = assert : and ([] : List Bool) ≡ True + +in and diff --git a/dhall/Prelude/Bool/build b/dhall/Prelude/Bool/build new file mode 100644 index 0000000..50ed231 --- /dev/null +++ b/dhall/Prelude/Bool/build @@ -0,0 +1,3 @@ + missing + sha256:add7cb9acacac705410088d876a7e4488e046a7aded304f06c51accffd7f1b7b +? ./build.dhall diff --git a/dhall/Prelude/Bool/build.dhall b/dhall/Prelude/Bool/build.dhall new file mode 100644 index 0000000..03f3c81 --- /dev/null +++ b/dhall/Prelude/Bool/build.dhall @@ -0,0 +1,16 @@ +--| `build` is the inverse of `fold` +let build + : (∀(bool : Type) → ∀(true : bool) → ∀(false : bool) → bool) → Bool + = λ(f : ∀(bool : Type) → ∀(true : bool) → ∀(false : bool) → bool) → + f Bool True False + +let example0 = + assert + : build (λ(bool : Type) → λ(true : bool) → λ(false : bool) → true) ≡ True + +let example1 = + assert + : build (λ(bool : Type) → λ(true : bool) → λ(false : bool) → false) + ≡ False + +in build diff --git a/dhall/Prelude/Bool/equal b/dhall/Prelude/Bool/equal new file mode 100644 index 0000000..d232676 --- /dev/null +++ b/dhall/Prelude/Bool/equal @@ -0,0 +1,3 @@ + missing + sha256:f0dc047ca14644c2a979bb126f2a3c6659ec770c66bd7beb70ae4a9d05815709 +? ./equal.dhall diff --git a/dhall/Prelude/Bool/equal.dhall b/dhall/Prelude/Bool/equal.dhall new file mode 100644 index 0000000..1ec1450 --- /dev/null +++ b/dhall/Prelude/Bool/equal.dhall @@ -0,0 +1,6 @@ +--| Returns `True` if both arguments are equal and returns `False` otherwise +let equal + : Bool -> Bool -> Bool + = \(x : Bool) -> \(y : Bool) -> x == y + +in equal diff --git a/dhall/Prelude/Bool/even b/dhall/Prelude/Bool/even new file mode 100644 index 0000000..0afde9b --- /dev/null +++ b/dhall/Prelude/Bool/even @@ -0,0 +1,3 @@ + missing + sha256:72a05ee550636a3acb768360fa51ba0db0326763e0cf1ceb737f0f3607fc0fe5 +? ./even.dhall diff --git a/dhall/Prelude/Bool/even.dhall b/dhall/Prelude/Bool/even.dhall new file mode 100644 index 0000000..9f5515e --- /dev/null +++ b/dhall/Prelude/Bool/even.dhall @@ -0,0 +1,20 @@ +{-| +Returns `True` if there are an even number of `False` elements in the list and +returns `False` otherwise. + +This function is the `Monoid` for the `==` operation. +-} +let even + : List Bool → Bool + = λ(xs : List Bool) → + List/fold Bool xs Bool (λ(x : Bool) → λ(y : Bool) → x == y) True + +let example0 = assert : even [ False, True, False ] ≡ True + +let example1 = assert : even [ False, True ] ≡ False + +let example2 = assert : even [ False ] ≡ False + +let example3 = assert : even ([] : List Bool) ≡ True + +in even diff --git a/dhall/Prelude/Bool/fold b/dhall/Prelude/Bool/fold new file mode 100644 index 0000000..ca3f5ff --- /dev/null +++ b/dhall/Prelude/Bool/fold @@ -0,0 +1,3 @@ + missing + sha256:39f60baf3950268c2e849e91dc6279ee41cd6b81892d54020d4fcd2ce30a96ae +? ./fold.dhall diff --git a/dhall/Prelude/Bool/fold.dhall b/dhall/Prelude/Bool/fold.dhall new file mode 100644 index 0000000..5bfcfbf --- /dev/null +++ b/dhall/Prelude/Bool/fold.dhall @@ -0,0 +1,14 @@ +--| `fold` is essentially the same as `if`/`then`/`else` except as a function +let fold + : ∀(b : Bool) → ∀(bool : Type) → ∀(true : bool) → ∀(false : bool) → bool + = λ(b : Bool) → + λ(bool : Type) → + λ(true : bool) → + λ(false : bool) → + if b then true else false + +let example0 = assert : fold True Natural 0 1 ≡ 0 + +let example1 = assert : fold False Natural 0 1 ≡ 1 + +in fold diff --git a/dhall/Prelude/Bool/not b/dhall/Prelude/Bool/not new file mode 100644 index 0000000..e90bb84 --- /dev/null +++ b/dhall/Prelude/Bool/not @@ -0,0 +1,3 @@ + missing + sha256:723df402df24377d8a853afed08d9d69a0a6d86e2e5b2bac8960b0d4756c7dc4 +? ./not.dhall diff --git a/dhall/Prelude/Bool/not.dhall b/dhall/Prelude/Bool/not.dhall new file mode 100644 index 0000000..3d58e9e --- /dev/null +++ b/dhall/Prelude/Bool/not.dhall @@ -0,0 +1,10 @@ +--| Flip the value of a `Bool` +let not + : Bool → Bool + = λ(b : Bool) → b == False + +let example0 = assert : not True ≡ False + +let example1 = assert : not False ≡ True + +in not diff --git a/dhall/Prelude/Bool/odd b/dhall/Prelude/Bool/odd new file mode 100644 index 0000000..ae4a655 --- /dev/null +++ b/dhall/Prelude/Bool/odd @@ -0,0 +1,3 @@ + missing + sha256:6360fca3a745de32bd186cc7b71487a6398cd47d5119064eae491872c41d1999 +? ./odd.dhall diff --git a/dhall/Prelude/Bool/odd.dhall b/dhall/Prelude/Bool/odd.dhall new file mode 100644 index 0000000..2c0d1d9 --- /dev/null +++ b/dhall/Prelude/Bool/odd.dhall @@ -0,0 +1,20 @@ +{-| +Returns `True` if there are an odd number of `True` elements in the list and +returns `False` otherwise. + +This function is the `Monoid` for the `!=` operation. +-} +let odd + : List Bool → Bool + = λ(xs : List Bool) → + List/fold Bool xs Bool (λ(x : Bool) → λ(y : Bool) → x != y) False + +let example0 = assert : odd [ True, False, True ] ≡ False + +let example1 = assert : odd [ True, False ] ≡ True + +let example2 = assert : odd [ True ] ≡ True + +let example3 = assert : odd ([] : List Bool) ≡ False + +in odd diff --git a/dhall/Prelude/Bool/or b/dhall/Prelude/Bool/or new file mode 100644 index 0000000..62520d3 --- /dev/null +++ b/dhall/Prelude/Bool/or @@ -0,0 +1,3 @@ + missing + sha256:5c50738e84e1c4fed8343ebd57608500e1b61ac1f502aa52d6d6edb5c20b99e4 +? ./or.dhall diff --git a/dhall/Prelude/Bool/or.dhall b/dhall/Prelude/Bool/or.dhall new file mode 100644 index 0000000..6f1642c --- /dev/null +++ b/dhall/Prelude/Bool/or.dhall @@ -0,0 +1,14 @@ +{-| +The `or` function returns `True` if there are any `True` elements in the `List` +and returns `False` otherwise +-} +let or + : List Bool → Bool + = λ(xs : List Bool) → + List/fold Bool xs Bool (λ(l : Bool) → λ(r : Bool) → l || r) False + +let example0 = assert : or [ True, False, True ] ≡ True + +let example1 = assert : or ([] : List Bool) ≡ False + +in or diff --git a/dhall/Prelude/Bool/package.dhall b/dhall/Prelude/Bool/package.dhall new file mode 100644 index 0000000..c9eaa60 --- /dev/null +++ b/dhall/Prelude/Bool/package.dhall @@ -0,0 +1,37 @@ +{ and = + missing + sha256:0b2114fa33cd76652e4360f012bc082718944fe4c5b28c975483178f8d9b0a6d + ? ./and.dhall +, build = + missing + sha256:add7cb9acacac705410088d876a7e4488e046a7aded304f06c51accffd7f1b7b + ? ./build.dhall +, equal = + missing + sha256:f0dc047ca14644c2a979bb126f2a3c6659ec770c66bd7beb70ae4a9d05815709 + ? ./equal.dhall +, even = + missing + sha256:72a05ee550636a3acb768360fa51ba0db0326763e0cf1ceb737f0f3607fc0fe5 + ? ./even.dhall +, fold = + missing + sha256:39f60baf3950268c2e849e91dc6279ee41cd6b81892d54020d4fcd2ce30a96ae + ? ./fold.dhall +, not = + missing + sha256:723df402df24377d8a853afed08d9d69a0a6d86e2e5b2bac8960b0d4756c7dc4 + ? ./not.dhall +, odd = + missing + sha256:6360fca3a745de32bd186cc7b71487a6398cd47d5119064eae491872c41d1999 + ? ./odd.dhall +, or = + missing + sha256:5c50738e84e1c4fed8343ebd57608500e1b61ac1f502aa52d6d6edb5c20b99e4 + ? ./or.dhall +, show = + missing + sha256:f85f6d2d921c37a2122cb2e2f8a0170e305b699debd0e6df5ef3370d806b5f61 + ? ./show.dhall +} diff --git a/dhall/Prelude/Bool/show b/dhall/Prelude/Bool/show new file mode 100644 index 0000000..67f5324 --- /dev/null +++ b/dhall/Prelude/Bool/show @@ -0,0 +1,3 @@ + missing + sha256:f85f6d2d921c37a2122cb2e2f8a0170e305b699debd0e6df5ef3370d806b5f61 +? ./show.dhall diff --git a/dhall/Prelude/Bool/show.dhall b/dhall/Prelude/Bool/show.dhall new file mode 100644 index 0000000..434001e --- /dev/null +++ b/dhall/Prelude/Bool/show.dhall @@ -0,0 +1,13 @@ +{-| +Render a `Bool` as `Text` using the same representation as Dhall source code +(i.e. beginning with a capital letter) +-} +let show + : Bool → Text + = λ(b : Bool) → if b then "True" else "False" + +let example0 = assert : show True ≡ "True" + +let example1 = assert : show False ≡ "False" + +in show diff --git a/dhall/Prelude/Date/package.dhall b/dhall/Prelude/Date/package.dhall new file mode 100644 index 0000000..5452d3e --- /dev/null +++ b/dhall/Prelude/Date/package.dhall @@ -0,0 +1,5 @@ +{ show = + missing + sha256:8a0eb9732cbc3c8f161b7cb05b183493befacc4728d2d9b7ee1384f19106a5ff + ? ./show.dhall +} diff --git a/dhall/Prelude/Date/show.dhall b/dhall/Prelude/Date/show.dhall new file mode 100644 index 0000000..a8de1e6 --- /dev/null +++ b/dhall/Prelude/Date/show.dhall @@ -0,0 +1,15 @@ +{- +Render a `Date` as `Text` using the same representation as Dhall source code +(i.e. `YYYY-MM-DD`) +-} +let show + : Date → Text + = Date/show + +let example0 = assert : show 2000-09-02 ≡ "2000-09-02" + +let example1 = assert : show 9999-12-31 ≡ "9999-12-31" + +let example2 = assert : show 0000-01-01 ≡ "0000-01-01" + +in show diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/Type.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/Type.dhall new file mode 100644 index 0000000..5148faa --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/Type.dhall @@ -0,0 +1,5 @@ +{-| +A (total) set of access rights; See chmod(5) for an explanation of the flags. +For a partial set of of access rights see `Access`. +-} +{ execute : Bool, read : Bool, write : Bool } diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/intersect.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/intersect.dhall new file mode 100644 index 0000000..da1902e --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/intersect.dhall @@ -0,0 +1,69 @@ +{-| +@intersect a b@ intesects the flags of the two `Mask`s @a@ and @b@. This +resembles the bitwise "and", i.e. the value of a flag is 'True' if and only if +it is set to 'True' in both @a@ and @b@. As a consequence @intersect a rwx == a@ +and @intersect a none == none@ for all @a@. +-} +let Mask = + missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall + +let intersect + : Mask -> Mask -> Mask + = \(m1 : Mask) -> + \(m2 : Mask) -> + { read = m1.read && m2.read + , write = m1.write && m2.write + , execute = m1.execute && m2.execute + } + +let example0 = + let r = + missing + sha256:26d7fc8df6194a8051946eac88d0d7fecce690bff6819e69b3c74edf65ac027a + ? ./r.dhall + + let w = + missing + sha256:9d10dfc672f61bbb2828c7be2121aae2502938c25adb47bb8cce3c40ba99821b + ? ./w.dhall + + let x = + missing + sha256:a966fd88c05a5912a6daa8409e0c9e396f0a4810b51def1e1f62a95e18235f10 + ? ./x.dhall + + let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ./rwx.dhall + + let none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ./none.dhall + + in assert : intersect r (intersect w (intersect x rwx)) === none + +let example1 = + \(a : Mask) -> + let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ./rwx.dhall + + in assert + : intersect a rwx + === { execute = a.execute, read = a.read, write = a.write } + +let example2 = + \(a : Mask) -> + let none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ./none.dhall + + in assert : intersect a none === none + +in intersect diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/invert.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/invert.dhall new file mode 100644 index 0000000..a0d04e7 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/invert.dhall @@ -0,0 +1,48 @@ +{-| +Inverts the flags set in a `Mask`. +-} +let Mask = + missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall + +let Bool/not = + missing + sha256:723df402df24377d8a853afed08d9d69a0a6d86e2e5b2bac8960b0d4756c7dc4 + ? ../../../Bool/not.dhall + +let invert + : Mask -> Mask + = \(m : Mask) -> + { read = Bool/not m.read + , write = Bool/not m.write + , execute = Bool/not m.execute + } + +let example0 = + let none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ./none.dhall + + let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ./rwx.dhall + + in assert : invert rwx === none + +let example1 = + let none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ./none.dhall + + let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ./rwx.dhall + + in assert : invert none === rwx + +in invert diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/none.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/none.dhall new file mode 100644 index 0000000..cda9b49 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/none.dhall @@ -0,0 +1,4 @@ + { read = False, write = False, execute = False } +: missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/package.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/package.dhall new file mode 100644 index 0000000..c33792d --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/package.dhall @@ -0,0 +1,53 @@ +{ Type = + missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall +, intersect = + missing + sha256:7c7dab3e305f43cba556e0778b5a797cf8e9b1d1a6c6f6fe0ea311c329919663 + ? ./intersect.dhall +, invert = + missing + sha256:8807fb02f694fe2117f8a7f794e5afbb967ec36eac3405184bf9232c33cdd830 + ? ./invert.dhall +, none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ./none.dhall +, r = + missing + sha256:26d7fc8df6194a8051946eac88d0d7fecce690bff6819e69b3c74edf65ac027a + ? ./r.dhall +, rw = + missing + sha256:c3cce19f462b841e64adafbdf2963699a0031f5fc08b041c8ad364483c544d8b + ? ./rw.dhall +, rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ./rwx.dhall +, rx = + missing + sha256:d9beaa853c0de6984c3e5b0e313b573942900f8024fd9aaad743d73df458dc5e + ? ./rx.dhall +, toAccess = + missing + sha256:78fe016f0273b2551c8590da71bf204cc26d6879c6b84622d4d8ad5624328438 + ? ./toAccess.dhall +, toAccessWith = + missing + sha256:814ab74ad292c121620a1f468837d4a5473323423bf68c1bceca69e7b3c59077 + ? ./toAccessWith.dhall +, union = + missing + sha256:b40c4cbb266991e3f764af075e9db544b59c16b3d9aa680c0cf6cb7552da191f + ? ./union.dhall +, w = + missing + sha256:9d10dfc672f61bbb2828c7be2121aae2502938c25adb47bb8cce3c40ba99821b + ? ./w.dhall +, x = + missing + sha256:a966fd88c05a5912a6daa8409e0c9e396f0a4810b51def1e1f62a95e18235f10 + ? ./x.dhall +} diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/r.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/r.dhall new file mode 100644 index 0000000..d50f297 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/r.dhall @@ -0,0 +1,4 @@ + { read = True, write = False, execute = False } +: missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/rw.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/rw.dhall new file mode 100644 index 0000000..8c07aaf --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/rw.dhall @@ -0,0 +1,4 @@ + { read = True, write = True, execute = False } +: missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/rwx.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/rwx.dhall new file mode 100644 index 0000000..61f1ae8 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/rwx.dhall @@ -0,0 +1,4 @@ + { read = True, write = True, execute = True } +: missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/rx.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/rx.dhall new file mode 100644 index 0000000..cea0309 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/rx.dhall @@ -0,0 +1,4 @@ + { read = True, write = False, execute = True } +: missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/toAccess.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/toAccess.dhall new file mode 100644 index 0000000..d1219f9 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/toAccess.dhall @@ -0,0 +1,20 @@ +{-| +Convert a `Mask` value to an `Access` value. For a partial conversion see +`toAccessWith`. +-} +let Access = + missing + sha256:50689ae80f8c8dcd6e7af33fbc20ea871afb92ec87104253cdbae01f838f6c38 + ? ../Type.dhall + +let Mask = + missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall + +let toAccess + : Mask -> Access + = \(m : Mask) -> + { execute = Some m.execute, read = Some m.read, write = Some m.write } + +in toAccess diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/toAccessWith.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/toAccessWith.dhall new file mode 100644 index 0000000..508c036 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/toAccessWith.dhall @@ -0,0 +1,42 @@ +{-| +@toAccessWith x m@ converts some fields of a `Mask` @m@ to an `Access` setting: +If the respective field is set in the first `Mask` @x@, then the flag will be +set to the flags value given in @m@. Otherwise, the value set in @m@ is ignored +and the value of the flag in the result is `None`. + +For a motivation of this function see the documenation on `toModeWith`. +-} +let Access = + missing + sha256:50689ae80f8c8dcd6e7af33fbc20ea871afb92ec87104253cdbae01f838f6c38 + ? ../Type.dhall + +let Mask = + missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall + +let toAccessWith + : Mask -> Mask -> Access + = \(set : Mask) -> + \(m : Mask) -> + { execute = if set.execute then Some m.execute else None Bool + , read = if set.read then Some m.read else None Bool + , write = if set.write then Some m.write else None Bool + } + +let example0 = + \(a : Mask) -> + let Access/none = + missing + sha256:955a2eed689139c811d4b9ef3dd8d0c484392b18c3bb8752c59fd69dbdaf4881 + ? ../none.dhall + + let none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ./none.dhall + + in assert : toAccessWith none a === Access/none + +in toAccessWith diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/union.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/union.dhall new file mode 100644 index 0000000..d3c44d2 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/union.dhall @@ -0,0 +1,64 @@ +{-| +@union a b@ combines the flags of the two `Mask`s @a@ and @b@. This resembles +the bitwise "or", i.e. the value of a flag is 'True' if it is set to 'True' in +either @a@ and @b@. As a consequence @union a rwx == rwx@ and +@union a none == a@ for all @a@. +-} +let Mask = + missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall + +let union + : Mask -> Mask -> Mask + = \(m1 : Mask) -> + \(m2 : Mask) -> + { read = m1.read || m2.read + , write = m1.write || m2.write + , execute = m1.execute || m2.execute + } + +let example0 = + let r = + missing + sha256:26d7fc8df6194a8051946eac88d0d7fecce690bff6819e69b3c74edf65ac027a + ? ./r.dhall + + let w = + missing + sha256:9d10dfc672f61bbb2828c7be2121aae2502938c25adb47bb8cce3c40ba99821b + ? ./w.dhall + + let x = + missing + sha256:a966fd88c05a5912a6daa8409e0c9e396f0a4810b51def1e1f62a95e18235f10 + ? ./x.dhall + + let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ./rwx.dhall + + in assert : union r (union w x) === rwx + +let example1 = + \(a : Mask) -> + let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ./rwx.dhall + + in assert : union a rwx === rwx + +let example1 = + \(a : Mask) -> + let none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ./none.dhall + + in assert + : union a none + === { execute = a.execute, read = a.read, write = a.write } + +in union diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/w.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/w.dhall new file mode 100644 index 0000000..1918719 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/w.dhall @@ -0,0 +1,4 @@ + { read = False, write = True, execute = False } +: missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Access/Mask/x.dhall b/dhall/Prelude/DirectoryTree/Access/Mask/x.dhall new file mode 100644 index 0000000..8d4be28 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Mask/x.dhall @@ -0,0 +1,4 @@ + { read = False, write = False, execute = True } +: missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Access/Type.dhall b/dhall/Prelude/DirectoryTree/Access/Type.dhall new file mode 100644 index 0000000..1cf6f32 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/Type.dhall @@ -0,0 +1,5 @@ +{-| +A (partial) set of access rights; See chmod(5) for an explanation of the flags. +For a total set of access rights see `Mask`. +-} +{ execute : Optional Bool, read : Optional Bool, write : Optional Bool } diff --git a/dhall/Prelude/DirectoryTree/Access/equal.dhall b/dhall/Prelude/DirectoryTree/Access/equal.dhall new file mode 100644 index 0000000..e4428ce --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/equal.dhall @@ -0,0 +1,29 @@ +{-| +`equal` checks if two `Access` settings are equal. +-} +let Access = + missing + sha256:50689ae80f8c8dcd6e7af33fbc20ea871afb92ec87104253cdbae01f838f6c38 + ? ./Type.dhall + +let Bool/equal = + missing + sha256:f0dc047ca14644c2a979bb126f2a3c6659ec770c66bd7beb70ae4a9d05815709 + ? ../../Bool/equal.dhall + +let Optional/equal = + missing + sha256:5411888399fe9c6720f7f3b59caf5eff3e8e8c30402d09f34e46a4457649a35a + ? ../../Optional/equal.dhall + +let f + : Optional Bool -> Optional Bool -> Bool + = Optional/equal Bool Bool/equal + +let equal + : Access -> Access -> Bool + = \(a1 : Access) -> + \(a2 : Access) -> + f a1.execute a2.execute && f a1.read a2.read && f a1.write a2.write + +in equal diff --git a/dhall/Prelude/DirectoryTree/Access/none.dhall b/dhall/Prelude/DirectoryTree/Access/none.dhall new file mode 100644 index 0000000..f6e273c --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/none.dhall @@ -0,0 +1,4 @@ + { read = None Bool, write = None Bool, execute = None Bool } +: missing + sha256:50689ae80f8c8dcd6e7af33fbc20ea871afb92ec87104253cdbae01f838f6c38 + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Access/package.dhall b/dhall/Prelude/DirectoryTree/Access/package.dhall new file mode 100644 index 0000000..b0e499d --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/package.dhall @@ -0,0 +1,17 @@ +{ Mask = + missing + sha256:ed736de51ea15a2ef671eaa7219dfbf3138bb52acfd0ae17894acf2ec4b06369 + ? ./Mask/package.dhall +, Type = + missing + sha256:50689ae80f8c8dcd6e7af33fbc20ea871afb92ec87104253cdbae01f838f6c38 + ? ./Type.dhall +, equal = + missing + sha256:5fa90f55505780a7be942275d6bbb2b1f1fb7857364332ed732a0241c2165e53 + ? ./equal.dhall +, schema = + missing + sha256:7d33a584a42a5d92411d5ca623e27ccb397762905be86ecfd01b106719fae690 + ? ./schema.dhall +} diff --git a/dhall/Prelude/DirectoryTree/Access/schema.dhall b/dhall/Prelude/DirectoryTree/Access/schema.dhall new file mode 100644 index 0000000..77c8bb4 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Access/schema.dhall @@ -0,0 +1,12 @@ +{-| +A schema for blank access rights. +-} +{ Type = + missing + sha256:50689ae80f8c8dcd6e7af33fbc20ea871afb92ec87104253cdbae01f838f6c38 + ? ./Type.dhall +, default = + missing + sha256:955a2eed689139c811d4b9ef3dd8d0c484392b18c3bb8752c59fd69dbdaf4881 + ? ./none.dhall +} diff --git a/dhall/Prelude/DirectoryTree/Entry/DirectoryEntry.dhall b/dhall/Prelude/DirectoryTree/Entry/DirectoryEntry.dhall new file mode 100644 index 0000000..47fe90e --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Entry/DirectoryEntry.dhall @@ -0,0 +1,6 @@ +let Entry = + missing + sha256:75148ae19175750e38705e11cda8dcc775b2ac08f22518ff2ef3f33a6273ef15 + ? ./Type.dhall + +in \(tree : Type) -> Entry (List tree) diff --git a/dhall/Prelude/DirectoryTree/Entry/FileEntry.dhall b/dhall/Prelude/DirectoryTree/Entry/FileEntry.dhall new file mode 100644 index 0000000..296e8e9 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Entry/FileEntry.dhall @@ -0,0 +1,6 @@ +let Entry = + missing + sha256:75148ae19175750e38705e11cda8dcc775b2ac08f22518ff2ef3f33a6273ef15 + ? ./Type.dhall + +in Entry Text diff --git a/dhall/Prelude/DirectoryTree/Entry/Metadata.dhall b/dhall/Prelude/DirectoryTree/Entry/Metadata.dhall new file mode 100644 index 0000000..47f731c --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Entry/Metadata.dhall @@ -0,0 +1,24 @@ +{-| +An `Entry` without content. That in turn implies that the type of the entry +(i.e. whether it is a file or a directory) is not (yet) fixed as well. +-} +let User = + missing + sha256:8b25916612d2c9b17130d16b55c6bdb085dd118e692f72bf351a83b1d0ac8833 + ? ../User/Type.dhall + +let Group = + missing + sha256:83e6e8846153d94abf6f879808c94f5cdba3f486cc9e392eb6124b1dc67368cf + ? ../Group/Type.dhall + +let Mode = + missing + sha256:f05819ec2145e7dabf4aa167338bee6d326aabd81355dcf0b078e358bd34ec60 + ? ../Mode/Type.dhall + +in { name : Text + , user : Optional User + , group : Optional Group + , mode : Optional Mode + } diff --git a/dhall/Prelude/DirectoryTree/Entry/Type.dhall b/dhall/Prelude/DirectoryTree/Entry/Type.dhall new file mode 100644 index 0000000..4911be7 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Entry/Type.dhall @@ -0,0 +1,6 @@ +let Metadata = + missing + sha256:8c240a00094238a73904af63ac0924b3e6aba1655312f20a2a27f88554e2febe + ? ./Metadata.dhall + +in \(content : Type) -> Metadata //\\ { content : content } diff --git a/dhall/Prelude/DirectoryTree/Entry/directory.dhall b/dhall/Prelude/DirectoryTree/Entry/directory.dhall new file mode 100644 index 0000000..367e163 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Entry/directory.dhall @@ -0,0 +1,6 @@ +let Entry = + missing + sha256:742610b2a13e55ae6e344b54aa8a7ee1bfec8e8b313a1132eae9286309b520e6 + ? ./entry.dhall + +in \(tree : Type) -> Entry (List tree) diff --git a/dhall/Prelude/DirectoryTree/Entry/entry.dhall b/dhall/Prelude/DirectoryTree/Entry/entry.dhall new file mode 100644 index 0000000..3ce3fcf --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Entry/entry.dhall @@ -0,0 +1,24 @@ +let Entry = + missing + sha256:75148ae19175750e38705e11cda8dcc775b2ac08f22518ff2ef3f33a6273ef15 + ? ./Type.dhall + +let User = + missing + sha256:8b25916612d2c9b17130d16b55c6bdb085dd118e692f72bf351a83b1d0ac8833 + ? ../User/Type.dhall + +let Group = + missing + sha256:83e6e8846153d94abf6f879808c94f5cdba3f486cc9e392eb6124b1dc67368cf + ? ../Group/Type.dhall + +let Mode = + missing + sha256:f05819ec2145e7dabf4aa167338bee6d326aabd81355dcf0b078e358bd34ec60 + ? ../Mode/Type.dhall + +in \(content : Type) -> + { Type = Entry content + , default = { user = None User, group = None Group, mode = None Mode } + } diff --git a/dhall/Prelude/DirectoryTree/Entry/file.dhall b/dhall/Prelude/DirectoryTree/Entry/file.dhall new file mode 100644 index 0000000..a2cfb88 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Entry/file.dhall @@ -0,0 +1,6 @@ +let Entry = + missing + sha256:742610b2a13e55ae6e344b54aa8a7ee1bfec8e8b313a1132eae9286309b520e6 + ? ./entry.dhall + +in Entry Text diff --git a/dhall/Prelude/DirectoryTree/Entry/package.dhall b/dhall/Prelude/DirectoryTree/Entry/package.dhall new file mode 100644 index 0000000..261e75c --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Entry/package.dhall @@ -0,0 +1,29 @@ +{ Directory = + missing + sha256:163a4536fdd05ce122d793ceda01d03fcffb29463817ae8b7b5601bf4a06ce6e + ? ./DirectoryEntry.dhall +, File = + missing + sha256:23a8cb29d96aeb623501519d9a62c5c49659e8d1c30b4ae4f2399809e3fd3a01 + ? ./FileEntry.dhall +, Metadata = + missing + sha256:8c240a00094238a73904af63ac0924b3e6aba1655312f20a2a27f88554e2febe + ? ./Metadata.dhall +, Type = + missing + sha256:75148ae19175750e38705e11cda8dcc775b2ac08f22518ff2ef3f33a6273ef15 + ? ./Type.dhall +, directory = + missing + sha256:0bee17310a21efa5b06f139b6731fdcee4f9e0245ef711c2b0127b8938dfed2e + ? ./directory.dhall +, entry = + missing + sha256:742610b2a13e55ae6e344b54aa8a7ee1bfec8e8b313a1132eae9286309b520e6 + ? ./entry.dhall +, file = + missing + sha256:c5d76fd43216668d03df9945183fe7b3c55486aedcc77324c3372bd63e283b78 + ? ./file.dhall +} diff --git a/dhall/Prelude/DirectoryTree/Group/Type.dhall b/dhall/Prelude/DirectoryTree/Group/Type.dhall new file mode 100644 index 0000000..67d0729 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Group/Type.dhall @@ -0,0 +1 @@ +< GroupId : Natural | GroupName : Text > diff --git a/dhall/Prelude/DirectoryTree/Group/id.dhall b/dhall/Prelude/DirectoryTree/Group/id.dhall new file mode 100644 index 0000000..1a0cac0 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Group/id.dhall @@ -0,0 +1,6 @@ +let Group = + missing + sha256:83e6e8846153d94abf6f879808c94f5cdba3f486cc9e392eb6124b1dc67368cf + ? ./Type.dhall + +in Group.GroupId diff --git a/dhall/Prelude/DirectoryTree/Group/name.dhall b/dhall/Prelude/DirectoryTree/Group/name.dhall new file mode 100644 index 0000000..6bd98c1 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Group/name.dhall @@ -0,0 +1,6 @@ +let Group = + missing + sha256:83e6e8846153d94abf6f879808c94f5cdba3f486cc9e392eb6124b1dc67368cf + ? ./Type.dhall + +in Group.GroupName diff --git a/dhall/Prelude/DirectoryTree/Group/package.dhall b/dhall/Prelude/DirectoryTree/Group/package.dhall new file mode 100644 index 0000000..6cefdbf --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Group/package.dhall @@ -0,0 +1,13 @@ +{ Type = + missing + sha256:83e6e8846153d94abf6f879808c94f5cdba3f486cc9e392eb6124b1dc67368cf + ? ./Type.dhall +, id = + missing + sha256:2bf9e546f56a583243d419a652caba16ca4053df9ccb3c5b242506d86806944b + ? ./id.dhall +, name = + missing + sha256:51ac5c407f2939ab0c80bf2896d292ee6049bd8ba10acda0af327a3777f2205d + ? ./name.dhall +} diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/Type.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/Type.dhall new file mode 100644 index 0000000..a6df5df --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/Type.dhall @@ -0,0 +1,10 @@ +{-| +A complete mode with all access rights specified explicitely. For an incomplete +mode where some access rights might not be set see `Mode`. +-} +let Access/Mask = + missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ../../Access/Mask/Type.dhall + +in { user : Access/Mask, group : Access/Mask, other : Access/Mask } diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/all.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/all.dhall new file mode 100644 index 0000000..4eaf4e5 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/all.dhall @@ -0,0 +1,9 @@ +{-| +Permissions with all flags set: rwxrwxrwx +-} +let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ../../Access/Mask/rwx.dhall + +in { user = rwx, group = rwx, other = rwx } diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/directory.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/directory.dhall new file mode 100644 index 0000000..12e36ec --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/directory.dhall @@ -0,0 +1,17 @@ +{-| +Permissions commonly used for directories: rwxr-xr-x +-} +let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ../../Access/Mask/rwx.dhall + +let rx = + missing + sha256:d9beaa853c0de6984c3e5b0e313b573942900f8024fd9aaad743d73df458dc5e + ? ../../Access/Mask/rx.dhall + +in { user = rwx, group = rx, other = rx } + : missing + sha256:4f97762058f24053e03997565a78800a5a2586159deaa265a4ee84a3d94ad471 + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/executable.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/executable.dhall new file mode 100644 index 0000000..3eb7bce --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/executable.dhall @@ -0,0 +1,17 @@ +{-| +Permissions commonly used for executable files: rwxr-xr-x +-} +let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ../../Access/Mask/rwx.dhall + +let rx = + missing + sha256:d9beaa853c0de6984c3e5b0e313b573942900f8024fd9aaad743d73df458dc5e + ? ../../Access/Mask/rx.dhall + +in { user = rwx, group = rx, other = rx } + : missing + sha256:4f97762058f24053e03997565a78800a5a2586159deaa265a4ee84a3d94ad471 + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/file.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/file.dhall new file mode 100644 index 0000000..f0bc2ad --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/file.dhall @@ -0,0 +1,17 @@ +{-| +Permissions commonly used for regular files: rw-r--r-- +-} +let r = + missing + sha256:26d7fc8df6194a8051946eac88d0d7fecce690bff6819e69b3c74edf65ac027a + ? ../../Access/Mask/r.dhall + +let rw = + missing + sha256:c3cce19f462b841e64adafbdf2963699a0031f5fc08b041c8ad364483c544d8b + ? ../../Access/Mask/rw.dhall + +in { user = rw, group = r, other = r } + : missing + sha256:4f97762058f24053e03997565a78800a5a2586159deaa265a4ee84a3d94ad471 + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/group.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/group.dhall new file mode 100644 index 0000000..6576fb8 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/group.dhall @@ -0,0 +1,14 @@ +{-| +Permissions with group flags set: ---rwx--- +-} +let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ../../Access/Mask/rwx.dhall + +let none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ../../Access/Mask/none.dhall + +in { user = none, group = rwx, other = none } diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/intersect.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/intersect.dhall new file mode 100644 index 0000000..ecfdded --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/intersect.dhall @@ -0,0 +1,24 @@ +{-| +Calculates the intersection of the access rights of two `Mask`s using +`Access/intersect`. +-} +let Mask = + missing + sha256:4f97762058f24053e03997565a78800a5a2586159deaa265a4ee84a3d94ad471 + ? ./Type.dhall + +let Access/intersect = + missing + sha256:7c7dab3e305f43cba556e0778b5a797cf8e9b1d1a6c6f6fe0ea311c329919663 + ? ../../Access/Mask/intersect.dhall + +let intersect + : Mask -> Mask -> Mask + = \(m1 : Mask) -> + \(m2 : Mask) -> + { user = Access/intersect m1.user m2.user + , group = Access/intersect m1.group m2.group + , other = Access/intersect m1.other m2.other + } + +in intersect diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/invert.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/invert.dhall new file mode 100644 index 0000000..be3c565 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/invert.dhall @@ -0,0 +1,22 @@ +{-| +Inverts each access right set in a `Mask` using `Access/invert`. +-} +let Mask = + missing + sha256:4f97762058f24053e03997565a78800a5a2586159deaa265a4ee84a3d94ad471 + ? ./Type.dhall + +let Access/invert = + missing + sha256:8807fb02f694fe2117f8a7f794e5afbb967ec36eac3405184bf9232c33cdd830 + ? ../../Access/Mask/invert.dhall + +let invert + : Mask -> Mask + = \(m : Mask) -> + { user = Access/invert m.user + , group = Access/invert m.group + , other = Access/invert m.other + } + +in invert diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/none.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/none.dhall new file mode 100644 index 0000000..6f4ea2d --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/none.dhall @@ -0,0 +1,12 @@ +{-| +Permissions with no flags set: --------- +-} +let none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ../../Access/Mask/none.dhall + +in { user = none, group = none, other = none } + : missing + sha256:4f97762058f24053e03997565a78800a5a2586159deaa265a4ee84a3d94ad471 + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/other.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/other.dhall new file mode 100644 index 0000000..15e0ed5 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/other.dhall @@ -0,0 +1,14 @@ +{-| +Permissions with other flags set: ------rwx +-} +let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ../../Access/Mask/rwx.dhall + +let none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ../../Access/Mask/none.dhall + +in { user = none, group = none, other = rwx } diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/package.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/package.dhall new file mode 100644 index 0000000..0e7ccbf --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/package.dhall @@ -0,0 +1,41 @@ +{ Type = + missing + sha256:4f97762058f24053e03997565a78800a5a2586159deaa265a4ee84a3d94ad471 + ? ./Type.dhall +, directory = + missing + sha256:a43f235f0caa25c7cabd89ac5d77e466e0c0ebf3339046993c18e481930243fd + ? ./directory.dhall +, executable = + missing + sha256:a43f235f0caa25c7cabd89ac5d77e466e0c0ebf3339046993c18e481930243fd + ? ./executable.dhall +, file = + missing + sha256:32d34228d48a707996272d1c9681171ddcd6651f72eeb3de9727d1c26ba99df3 + ? ./file.dhall +, intersect = + missing + sha256:146be962523ef619d3a250699f977b69c3e5f6c24b975453f351c0e807266fc8 + ? ./intersect.dhall +, invert = + missing + sha256:07a13d8c233d0a9fd6b3a11475987c10619072fec882c96bc5499bfb3c01e9b2 + ? ./invert.dhall +, none = + missing + sha256:7cac21e2b72cadf3ee0bf10680df4902ca73b6ee070219df5eac1a24cd66ccdf + ? ./none.dhall +, toMode = + missing + sha256:af2b0dab799374afa0a2f28551446760ff29f4697c200da0a8b0a8def7feee2a + ? ./toMode.dhall +, toModeWith = + missing + sha256:b92327bec9141cc1a55bc3f11ae2584af0883b94fe2513376fc40f1da5ade9b2 + ? ./toModeWith.dhall +, union = + missing + sha256:3bb32fc6ea21f661571e46d90e450e0340b2f2b65482ba7bd1a30514e1b39fc2 + ? ./union.dhall +} diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/toMode.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/toMode.dhall new file mode 100644 index 0000000..b0dbacd --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/toMode.dhall @@ -0,0 +1,28 @@ +{-| +Convert a `Mask` value to a `Mode` value. For a partial conversion see +`toModeWith`. +-} +let Mode = + missing + sha256:f05819ec2145e7dabf4aa167338bee6d326aabd81355dcf0b078e358bd34ec60 + ? ../Type.dhall + +let Mask = + missing + sha256:4f97762058f24053e03997565a78800a5a2586159deaa265a4ee84a3d94ad471 + ? ./Type.dhall + +let Access/toAccess = + missing + sha256:78fe016f0273b2551c8590da71bf204cc26d6879c6b84622d4d8ad5624328438 + ? ../../Access/Mask/toAccess.dhall + +let toMode + : Mask -> Mode + = \(m : Mask) -> + { user = Some (Access/toAccess m.user) + , group = Some (Access/toAccess m.group) + , other = Some (Access/toAccess m.other) + } + +in toMode diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/toModeWith.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/toModeWith.dhall new file mode 100644 index 0000000..684e349 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/toModeWith.dhall @@ -0,0 +1,149 @@ +{-| +@toModeWith x m@ converts some fields of a `Mask` @m@ to a `Mode`: If the +respective field is set in the first `Mask` @x@, then the flag will be set to +the flags value given in @m@. Otherwise, the value set in @m@ is ignored and the +value of the flag in the result is `None`. + +The function is motivated by the following use case: +Alice has her umask set to 022 and new files will have permissions set to +rw-r--r--. Bob has the umask set to 077, hence newly created files will have +rw------- permissions. Now Eve distributes Dhall code writing a file with the +following mode to the filesystem: +```dhall +let mask = ./other.dhall + +let permissions = ./all.dhall + +in +toModeWith mask permissions +``` +The written file will have rw-r--rwx permissions for Alice and rw----rwx +permissions for Bob as the `toModeWith mask` produces a `Mode` that will only +apply the permissions for the 'other' part. +-} +let Access = + missing + sha256:50689ae80f8c8dcd6e7af33fbc20ea871afb92ec87104253cdbae01f838f6c38 + ? ../../Access/Type.dhall + +let Access/Mask = + missing + sha256:c0fa7626b69e117086439a7b4ee15d1a80e16e38fe2ccc13f55e6dd26030b4df + ? ../../Access/Mask/Type.dhall + +let Mode = + missing + sha256:f05819ec2145e7dabf4aa167338bee6d326aabd81355dcf0b078e358bd34ec60 + ? ../Type.dhall + +let Mask = + missing + sha256:4f97762058f24053e03997565a78800a5a2586159deaa265a4ee84a3d94ad471 + ? ./Type.dhall + +let Access/equal = + missing + sha256:5fa90f55505780a7be942275d6bbb2b1f1fb7857364332ed732a0241c2165e53 + ? ../../Access/equal.dhall + +let Access/toAccessWith = + missing + sha256:814ab74ad292c121620a1f468837d4a5473323423bf68c1bceca69e7b3c59077 + ? ../../Access/Mask/toAccessWith.dhall + +let f + : Access/Mask -> Access/Mask -> Optional Access + = \(set : Access/Mask) -> + \(m : Access/Mask) -> + let x = Access/toAccessWith set m + + in if Access/equal + { execute = None Bool, read = None Bool, write = None Bool } + x + then None Access + else Some x + +let toModeWith + : Mask -> Mask -> Mode + = \(set : Mask) -> + \(m : Mask) -> + { user = f set.user m.user + , group = f set.group m.group + , other = f set.other m.other + } + +let example0 = + \(a : Mask) -> + let none = + missing + sha256:7cac21e2b72cadf3ee0bf10680df4902ca73b6ee070219df5eac1a24cd66ccdf + ? ./none.dhall + + let Mode/none = + missing + sha256:0ed46da7e6acbdff9e4c9e27a9f2770075a7cd6cb6bb565765c62093df1b5563 + ? ../none.dhall + + in assert : toModeWith none a === Mode/none + +let example1 = + \(a : Mask) -> + let toMode = + missing + sha256:af2b0dab799374afa0a2f28551446760ff29f4697c200da0a8b0a8def7feee2a + ? ./toMode.dhall + + let all = + missing + sha256:758415eca8dfee675dfef93ace9af82abb36bb3319b8e6295537ed18f9b5d3dd + ? ./all.dhall + + in assert : toModeWith all a === toMode a + +let example2 = + let mask = + missing + sha256:94bf82678d8d1c4f370a96f3831d3ad4464fbee508ffb37e93a479a1d9ee25cf + ? ./other.dhall + + let permissions = + missing + sha256:758415eca8dfee675dfef93ace9af82abb36bb3319b8e6295537ed18f9b5d3dd + ? ./all.dhall + + let rwx = { read = Some True, write = Some True, execute = Some True } + + in assert + : toModeWith mask permissions + === { user = None Access, group = None Access, other = Some rwx } + +let example3 = + let union = + missing + sha256:3bb32fc6ea21f661571e46d90e450e0340b2f2b65482ba7bd1a30514e1b39fc2 + ? ./union.dhall + + let group = + missing + sha256:faa567630372f77bb5cd2fa4fe7cb4760d2f9f79e35df80917e6e0064decf7cf + ? ./group.dhall + + let other = + missing + sha256:94bf82678d8d1c4f370a96f3831d3ad4464fbee508ffb37e93a479a1d9ee25cf + ? ./other.dhall + + let permissions = + missing + sha256:758415eca8dfee675dfef93ace9af82abb36bb3319b8e6295537ed18f9b5d3dd + ? ./all.dhall + + let mask = union group other + + let rwx = { read = Some True, write = Some True, execute = Some True } + + in assert + : toModeWith mask permissions + === { user = None Access, group = Some rwx, other = Some rwx } + +in toModeWith diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/union.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/union.dhall new file mode 100644 index 0000000..0700d03 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/union.dhall @@ -0,0 +1,24 @@ +{-| +Calculates the union of the access rights set by both `Mask`s using +`Access/union`. +-} +let Mask = + missing + sha256:4f97762058f24053e03997565a78800a5a2586159deaa265a4ee84a3d94ad471 + ? ./Type.dhall + +let Access/union = + missing + sha256:b40c4cbb266991e3f764af075e9db544b59c16b3d9aa680c0cf6cb7552da191f + ? ../../Access/Mask/union.dhall + +let union + : Mask -> Mask -> Mask + = \(m1 : Mask) -> + \(m2 : Mask) -> + { user = Access/union m1.user m2.user + , group = Access/union m1.group m2.group + , other = Access/union m1.other m2.other + } + +in union diff --git a/dhall/Prelude/DirectoryTree/Mode/Mask/user.dhall b/dhall/Prelude/DirectoryTree/Mode/Mask/user.dhall new file mode 100644 index 0000000..9042e8f --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Mask/user.dhall @@ -0,0 +1,14 @@ +{-| +Permissions with all user flags set: rwx------ +-} +let rwx = + missing + sha256:cafda16b1ecc0d2f9a63f3aab229a02e18aebb054283c73e50517f1e3727cd27 + ? ../../Access/Mask/rwx.dhall + +let none = + missing + sha256:db6c3bb734bb3288441f2664379706052943eaba35c021326a600d41ca766925 + ? ../../Access/Mask/none.dhall + +in { user = rwx, group = none, other = none } diff --git a/dhall/Prelude/DirectoryTree/Mode/Type.dhall b/dhall/Prelude/DirectoryTree/Mode/Type.dhall new file mode 100644 index 0000000..14cb0d0 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/Type.dhall @@ -0,0 +1,10 @@ +{-| +An incomplete mode where some access rights might not be set explicitely. For a +complete mode with all access rights specified explicitely see `Mask`. +-} +let Access = + missing + sha256:50689ae80f8c8dcd6e7af33fbc20ea871afb92ec87104253cdbae01f838f6c38 + ? ../Access/Type.dhall + +in { user : Optional Access, group : Optional Access, other : Optional Access } diff --git a/dhall/Prelude/DirectoryTree/Mode/equal.dhall b/dhall/Prelude/DirectoryTree/Mode/equal.dhall new file mode 100644 index 0000000..c769a90 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/equal.dhall @@ -0,0 +1,34 @@ +{-| +`equal` checks if two `Mode`s are equal. +-} +let Access = + missing + sha256:50689ae80f8c8dcd6e7af33fbc20ea871afb92ec87104253cdbae01f838f6c38 + ? ../Access/Type.dhall + +let Mode = + missing + sha256:f05819ec2145e7dabf4aa167338bee6d326aabd81355dcf0b078e358bd34ec60 + ? ./Type.dhall + +let Access/equal = + missing + sha256:5fa90f55505780a7be942275d6bbb2b1f1fb7857364332ed732a0241c2165e53 + ? ../Access/equal.dhall + +let Optional/equal = + missing + sha256:5411888399fe9c6720f7f3b59caf5eff3e8e8c30402d09f34e46a4457649a35a + ? ../../Optional/equal.dhall + +let f + : Optional Access -> Optional Access -> Bool + = Optional/equal Access Access/equal + +let equal + : Mode -> Mode -> Bool + = \(m1 : Mode) -> + \(m2 : Mode) -> + f m1.user m2.user && f m1.group m2.group && f m1.other m2.other + +in equal diff --git a/dhall/Prelude/DirectoryTree/Mode/none.dhall b/dhall/Prelude/DirectoryTree/Mode/none.dhall new file mode 100644 index 0000000..65fe787 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/none.dhall @@ -0,0 +1,9 @@ +let Access = + missing + sha256:50689ae80f8c8dcd6e7af33fbc20ea871afb92ec87104253cdbae01f838f6c38 + ? ../Access/Type.dhall + +in { user = None Access, group = None Access, other = None Access } + : missing + sha256:f05819ec2145e7dabf4aa167338bee6d326aabd81355dcf0b078e358bd34ec60 + ? ./Type.dhall diff --git a/dhall/Prelude/DirectoryTree/Mode/package.dhall b/dhall/Prelude/DirectoryTree/Mode/package.dhall new file mode 100644 index 0000000..e4dcb80 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/package.dhall @@ -0,0 +1,17 @@ +{ Mask = + missing + sha256:ce2c7ac1b81c2184b906cdd07c79936ba0eaf0445f1e383f53fd18d688ee7044 + ? ./Mask/package.dhall +, Type = + missing + sha256:f05819ec2145e7dabf4aa167338bee6d326aabd81355dcf0b078e358bd34ec60 + ? ./Type.dhall +, equal = + missing + sha256:32fee2d3a56a2162d6c98fb63d47d31f98b352f22cc60c8b506011c9b5230e56 + ? ./equal.dhall +, schema = + missing + sha256:49f8eff9612d761c1bd424299b68317ad0f3ba325e4d22ec8acb550c2f1c0a40 + ? ./schema.dhall +} diff --git a/dhall/Prelude/DirectoryTree/Mode/schema.dhall b/dhall/Prelude/DirectoryTree/Mode/schema.dhall new file mode 100644 index 0000000..ca18ca9 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Mode/schema.dhall @@ -0,0 +1,12 @@ +{-| +A schema for a blank file mode. +-} +{ Type = + missing + sha256:f05819ec2145e7dabf4aa167338bee6d326aabd81355dcf0b078e358bd34ec60 + ? ./Type.dhall +, default = + missing + sha256:0ed46da7e6acbdff9e4c9e27a9f2770075a7cd6cb6bb565765c62093df1b5563 + ? ./none.dhall +} diff --git a/dhall/Prelude/DirectoryTree/Tree/Make.dhall b/dhall/Prelude/DirectoryTree/Tree/Make.dhall new file mode 100644 index 0000000..df0aa5b --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Tree/Make.dhall @@ -0,0 +1,12 @@ +let Directory = + missing + sha256:163a4536fdd05ce122d793ceda01d03fcffb29463817ae8b7b5601bf4a06ce6e + ? ../Entry/DirectoryEntry.dhall + +let File = + missing + sha256:23a8cb29d96aeb623501519d9a62c5c49659e8d1c30b4ae4f2399809e3fd3a01 + ? ../Entry/FileEntry.dhall + +in \(tree : Type) -> + { directory : Directory tree -> tree, file : File -> tree } diff --git a/dhall/Prelude/DirectoryTree/Tree/Type.dhall b/dhall/Prelude/DirectoryTree/Tree/Type.dhall new file mode 100644 index 0000000..29134c8 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Tree/Type.dhall @@ -0,0 +1,6 @@ +let Make = + missing + sha256:235d511ed943dded33b46b1717df263037329394e27fb4b9c677eda5af924458 + ? ./Make.dhall + +in forall (tree : Type) -> forall (make : Make tree) -> List tree diff --git a/dhall/Prelude/DirectoryTree/Tree/makeTree.dhall b/dhall/Prelude/DirectoryTree/Tree/makeTree.dhall new file mode 100644 index 0000000..23c5a97 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Tree/makeTree.dhall @@ -0,0 +1,32 @@ +{-| +@makeTree tree make parents x@ places the tree @x@ below the directory @parent@. +@parent@ is given as a list of 'Metadata' values where each of those will be +used to create the respective level of the directory tree. +-} +let Make = + missing + sha256:235d511ed943dded33b46b1717df263037329394e27fb4b9c677eda5af924458 + ? ./Make.dhall + +let Metadata = + missing + sha256:8c240a00094238a73904af63ac0924b3e6aba1655312f20a2a27f88554e2febe + ? ../Entry/Metadata.dhall + +let makeTree + : forall (tree : Type) -> Make tree -> List Metadata -> tree -> tree + = \(tree : Type) -> + \(make : Make tree) -> + \(parents : List Metadata) -> + \(leaf : tree) -> + List/fold + Metadata + parents + tree + ( \(directory : Metadata) -> + \(result : tree) -> + make.directory (directory /\ { content = [ result ] }) + ) + leaf + +in makeTree diff --git a/dhall/Prelude/DirectoryTree/Tree/makeTreeFromList.dhall b/dhall/Prelude/DirectoryTree/Tree/makeTreeFromList.dhall new file mode 100644 index 0000000..c0c17a7 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Tree/makeTreeFromList.dhall @@ -0,0 +1,42 @@ +{-| +@makeTreeFromList tree make parents xs@ places the trees @xs@ below the +directory @parent@. @parent@ is given as a non-empty list of 'Metadata' values +where each of those will be used to create the respective level of the directory +tree. +-} +let Make = + missing + sha256:235d511ed943dded33b46b1717df263037329394e27fb4b9c677eda5af924458 + ? ./Make.dhall + +let Metadata = + missing + sha256:8c240a00094238a73904af63ac0924b3e6aba1655312f20a2a27f88554e2febe + ? ../Entry/Metadata.dhall + +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ../../NonEmpty/Type.dhall + +let makeTreesFromList = + missing + sha256:34ed54a0fc4072cbcb32d0b40adc3ad4e5d978c8dcd7fece9670bf0616f4ab18 + ? ./makeTreesFromList.dhall + +let makeTreeFromList + : forall (tree : Type) -> + Make tree -> + NonEmpty Metadata -> + List tree -> + tree + = \(tree : Type) -> + \(make : Make tree) -> + \(parents : NonEmpty Metadata) -> + \(leaves : List tree) -> + make.directory + ( parents.head + /\ { content = makeTreesFromList tree make parents.tail leaves } + ) + +in makeTreeFromList diff --git a/dhall/Prelude/DirectoryTree/Tree/makeTreesFromList.dhall b/dhall/Prelude/DirectoryTree/Tree/makeTreesFromList.dhall new file mode 100644 index 0000000..222587e --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Tree/makeTreesFromList.dhall @@ -0,0 +1,36 @@ +{-| +@makeTreesFromList tree make parents xs@ places the trees @xs@ below the +directory @parent@. @parent@ is given as a list of 'Metadata' values where each +of those will be used to create the respective level of the directory tree. +-} +let Make = + missing + sha256:235d511ed943dded33b46b1717df263037329394e27fb4b9c677eda5af924458 + ? ./Make.dhall + +let Metadata = + missing + sha256:8c240a00094238a73904af63ac0924b3e6aba1655312f20a2a27f88554e2febe + ? ../Entry/Metadata.dhall + +let makeTreesFromList + : forall (tree : Type) -> + Make tree -> + List Metadata -> + List tree -> + List tree + = \(tree : Type) -> + \(make : Make tree) -> + \(parents : List Metadata) -> + \(leaves : List tree) -> + List/fold + Metadata + parents + (List tree) + ( \(directory : Metadata) -> + \(content : List tree) -> + [ make.directory (directory /\ { content }) ] + ) + leaves + +in makeTreesFromList diff --git a/dhall/Prelude/DirectoryTree/Tree/package.dhall b/dhall/Prelude/DirectoryTree/Tree/package.dhall new file mode 100644 index 0000000..324f707 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/Tree/package.dhall @@ -0,0 +1,21 @@ +{ Make = + missing + sha256:235d511ed943dded33b46b1717df263037329394e27fb4b9c677eda5af924458 + ? ./Make.dhall +, Type = + missing + sha256:01820cec8324cb701b6cc99e1dbbc8aacf0115db7795c6c3a023e4f1818fea79 + ? ./Type.dhall +, makeTree = + missing + sha256:e67054bceeb8f55968d89dbaa4b60b726a4ec544e49bd0c5622d5b487610e804 + ? ./makeTree.dhall +, makeTreeFromList = + missing + sha256:ca73533264b52ed9eb29f51e7ac6dfc83c94c9051c5c52486d84b4a3ef7f0274 + ? ./makeTreeFromList.dhall +, makeTreesFromList = + missing + sha256:34ed54a0fc4072cbcb32d0b40adc3ad4e5d978c8dcd7fece9670bf0616f4ab18 + ? ./makeTreesFromList.dhall +} diff --git a/dhall/Prelude/DirectoryTree/User/Type.dhall b/dhall/Prelude/DirectoryTree/User/Type.dhall new file mode 100644 index 0000000..bcf626c --- /dev/null +++ b/dhall/Prelude/DirectoryTree/User/Type.dhall @@ -0,0 +1 @@ +< UserId : Natural | UserName : Text > diff --git a/dhall/Prelude/DirectoryTree/User/id.dhall b/dhall/Prelude/DirectoryTree/User/id.dhall new file mode 100644 index 0000000..aa4e839 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/User/id.dhall @@ -0,0 +1,6 @@ +let User = + missing + sha256:8b25916612d2c9b17130d16b55c6bdb085dd118e692f72bf351a83b1d0ac8833 + ? ./Type.dhall + +in User.UserId diff --git a/dhall/Prelude/DirectoryTree/User/name.dhall b/dhall/Prelude/DirectoryTree/User/name.dhall new file mode 100644 index 0000000..d98e2f4 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/User/name.dhall @@ -0,0 +1,6 @@ +let User = + missing + sha256:8b25916612d2c9b17130d16b55c6bdb085dd118e692f72bf351a83b1d0ac8833 + ? ./Type.dhall + +in User.UserName diff --git a/dhall/Prelude/DirectoryTree/User/package.dhall b/dhall/Prelude/DirectoryTree/User/package.dhall new file mode 100644 index 0000000..aec52c3 --- /dev/null +++ b/dhall/Prelude/DirectoryTree/User/package.dhall @@ -0,0 +1,13 @@ +{ Type = + missing + sha256:8b25916612d2c9b17130d16b55c6bdb085dd118e692f72bf351a83b1d0ac8833 + ? ./Type.dhall +, id = + missing + sha256:b572ca9f08a04e8e472f1b6141fd71ff27cc7f22d1e72be50eba5f54798b5a6d + ? ./id.dhall +, name = + missing + sha256:9cfd68599bbd626d3f32c9caa3f09b358ecc08659ef2540b24a4b17b49027015 + ? ./name.dhall +} diff --git a/dhall/Prelude/DirectoryTree/package.dhall b/dhall/Prelude/DirectoryTree/package.dhall new file mode 100644 index 0000000..844b07c --- /dev/null +++ b/dhall/Prelude/DirectoryTree/package.dhall @@ -0,0 +1,25 @@ +{ Access = + missing + sha256:12f2ac90297a81c6e5a548bbf568fc7c93c906a6528432aa74faab6ec859de30 + ? ./Access/package.dhall +, Entry = + missing + sha256:86da03766dbfeab3750ecd1012f6155dd904024351be20085dac3c79f27b22c7 + ? ./Entry/package.dhall +, Group = + missing + sha256:76a0d7e4606bdb91ab001b245cbd411939333b3fc3934ecbb5d41982d1ea001f + ? ./Group/package.dhall +, Mode = + missing + sha256:6687ff7703fe9abdc4af9b3404af3d1c7d21a523d10a0c0b57d102a0bd87843f + ? ./Mode/package.dhall +, Tree = + missing + sha256:d2cb84de6b084bfaeb42e6212e7085be9ee03ff2684cf9d04e0d8b4478f42aa7 + ? ./Tree/package.dhall +, User = + missing + sha256:eee7762ea4769371278907a4e33b3808d88430dda32dfc0536dc9bb2bb49d46a + ? ./User/package.dhall +} diff --git a/dhall/Prelude/Double/package.dhall b/dhall/Prelude/Double/package.dhall new file mode 100644 index 0000000..6556150 --- /dev/null +++ b/dhall/Prelude/Double/package.dhall @@ -0,0 +1,5 @@ +{ show = + missing + sha256:ae645813cc4d8505a265df4d7564c95482f62bb3e07fc81681959599b6cee04f + ? ./show.dhall +} diff --git a/dhall/Prelude/Double/show b/dhall/Prelude/Double/show new file mode 100644 index 0000000..9375561 --- /dev/null +++ b/dhall/Prelude/Double/show @@ -0,0 +1,3 @@ + missing + sha256:ae645813cc4d8505a265df4d7564c95482f62bb3e07fc81681959599b6cee04f +? ./show.dhall diff --git a/dhall/Prelude/Double/show.dhall b/dhall/Prelude/Double/show.dhall new file mode 100644 index 0000000..443515d --- /dev/null +++ b/dhall/Prelude/Double/show.dhall @@ -0,0 +1,13 @@ +{-| +Render a `Double` as `Text` using the same representation as Dhall source +code (i.e. a decimal floating point number with a leading `-` sign if negative) +-} +let show + : Double → Text + = Double/show + +let example0 = assert : show -3.1 ≡ "-3.1" + +let example1 = assert : show 0.4 ≡ "0.4" + +in show diff --git a/dhall/Prelude/Function/compose b/dhall/Prelude/Function/compose new file mode 100644 index 0000000..b20085d --- /dev/null +++ b/dhall/Prelude/Function/compose @@ -0,0 +1,3 @@ + missing + sha256:65ad8bbea530b3d8968785a7cf4a9a7976b67059aa15e3b61fcba600a40ae013 +? ./compose.dhall diff --git a/dhall/Prelude/Function/compose.dhall b/dhall/Prelude/Function/compose.dhall new file mode 100644 index 0000000..3931702 --- /dev/null +++ b/dhall/Prelude/Function/compose.dhall @@ -0,0 +1,17 @@ +--| Compose two functions into one. +let compose + : ∀(a : Type) → ∀(b : Type) → ∀(c : Type) → (a → b) → (b → c) → a → c + = λ(A : Type) → + λ(B : Type) → + λ(C : Type) → + λ(f : A → B) → + λ(g : B → C) → + λ(x : A) → + g (f x) + +let example0 = + assert + : compose Natural Natural Bool (λ(n : Natural) → n + n) Natural/even 3 + ≡ True + +in compose diff --git a/dhall/Prelude/Function/identity b/dhall/Prelude/Function/identity new file mode 100644 index 0000000..b550c04 --- /dev/null +++ b/dhall/Prelude/Function/identity @@ -0,0 +1,3 @@ + missing + sha256:f78b96792b459cb664f41c6119bd8897dd04353a3343521d436cd82ad71cb4d4 +? ./identity.dhall diff --git a/dhall/Prelude/Function/identity.dhall b/dhall/Prelude/Function/identity.dhall new file mode 100644 index 0000000..40d3a67 --- /dev/null +++ b/dhall/Prelude/Function/identity.dhall @@ -0,0 +1,10 @@ +--| The identity function simply returns its input +let identity + : ∀(a : Type) → ∀(x : a) → a + = λ(a : Type) → λ(x : a) → x + +let example0 = assert : identity Natural 1 ≡ 1 + +let example1 = assert : identity Bool ≡ (λ(x : Bool) → x) + +in identity diff --git a/dhall/Prelude/Function/package.dhall b/dhall/Prelude/Function/package.dhall new file mode 100644 index 0000000..d33c181 --- /dev/null +++ b/dhall/Prelude/Function/package.dhall @@ -0,0 +1,9 @@ +{ compose = + missing + sha256:65ad8bbea530b3d8968785a7cf4a9a7976b67059aa15e3b61fcba600a40ae013 + ? ./compose.dhall +, identity = + missing + sha256:f78b96792b459cb664f41c6119bd8897dd04353a3343521d436cd82ad71cb4d4 + ? ./identity.dhall +} diff --git a/dhall/Prelude/Integer/abs b/dhall/Prelude/Integer/abs new file mode 100644 index 0000000..95931ce --- /dev/null +++ b/dhall/Prelude/Integer/abs @@ -0,0 +1,3 @@ + missing + sha256:35212fcbe1e60cb95b033a4a9c6e45befca4a298aa9919915999d09e69ddced1 +? ./abs.dhall diff --git a/dhall/Prelude/Integer/abs.dhall b/dhall/Prelude/Integer/abs.dhall new file mode 100644 index 0000000..f32770a --- /dev/null +++ b/dhall/Prelude/Integer/abs.dhall @@ -0,0 +1,15 @@ +--| Returns the absolute value of an `Integer`, i.e. its non-negative value. +let abs + : Integer → Natural + = λ(n : Integer) → + if Natural/isZero (Integer/clamp n) + then Integer/clamp (Integer/negate n) + else Integer/clamp n + +let example0 = assert : abs +7 ≡ 7 + +let example2 = assert : abs +0 ≡ 0 + +let example3 = assert : abs -3 ≡ 3 + +in abs diff --git a/dhall/Prelude/Integer/add b/dhall/Prelude/Integer/add new file mode 100644 index 0000000..00f6222 --- /dev/null +++ b/dhall/Prelude/Integer/add @@ -0,0 +1,3 @@ + missing + sha256:7da1306a0bf87c5668beead2a1db1b18861e53d7ce1f38057b2964b649f59c3b +? ./add.dhall diff --git a/dhall/Prelude/Integer/add.dhall b/dhall/Prelude/Integer/add.dhall new file mode 100644 index 0000000..b803796 --- /dev/null +++ b/dhall/Prelude/Integer/add.dhall @@ -0,0 +1,25 @@ +--| `add m n` computes `m + n`. +let Integer/subtract = + missing + sha256:a34d36272fa8ae4f1ec8b56222fe8dc8a2ec55ec6538b840de0cbe207b006fda + ? ./subtract.dhall + +let add + : Integer → Integer → Integer + = λ(m : Integer) → λ(n : Integer) → Integer/subtract (Integer/negate m) n + +let example0 = assert : add +3 +5 ≡ +8 + +let example1 = assert : add -3 -5 ≡ -8 + +let example2 = assert : add -4 +4 ≡ +0 + +let example3 = assert : add -3 +5 ≡ +2 + +let example4 = assert : add +3 -5 ≡ -2 + +let example5 = assert : add +0 -3 ≡ -3 + +let example6 = assert : add +0 +3 ≡ +3 + +in add diff --git a/dhall/Prelude/Integer/clamp b/dhall/Prelude/Integer/clamp new file mode 100644 index 0000000..de92e22 --- /dev/null +++ b/dhall/Prelude/Integer/clamp @@ -0,0 +1,3 @@ + missing + sha256:ea42096cf3e024fadfaf910e0b839005b0ea7514fff11e5a3950a77694d9c5d2 +? ./clamp.dhall diff --git a/dhall/Prelude/Integer/clamp.dhall b/dhall/Prelude/Integer/clamp.dhall new file mode 100644 index 0000000..c55f73d --- /dev/null +++ b/dhall/Prelude/Integer/clamp.dhall @@ -0,0 +1,14 @@ +{-| +Convert an `Integer` to a `Natural` number, with negative numbers becoming zero. +-} +let clamp + : Integer → Natural + = Integer/clamp + +let example0 = assert : clamp +7 ≡ 7 + +let example2 = assert : clamp +0 ≡ 0 + +let example3 = assert : clamp -3 ≡ 0 + +in clamp diff --git a/dhall/Prelude/Integer/equal b/dhall/Prelude/Integer/equal new file mode 100644 index 0000000..75538a4 --- /dev/null +++ b/dhall/Prelude/Integer/equal @@ -0,0 +1,3 @@ + missing + sha256:2d99a205086aa77eea17ae1dab22c275f3eb007bccdc8d9895b93497ebfc39f8 +? ./equal.dhall diff --git a/dhall/Prelude/Integer/equal.dhall b/dhall/Prelude/Integer/equal.dhall new file mode 100644 index 0000000..155e52a --- /dev/null +++ b/dhall/Prelude/Integer/equal.dhall @@ -0,0 +1,24 @@ +--| `equal` checks if two Integers are equal. +let Natural/equal = + missing + sha256:7f108edfa35ddc7cebafb24dc073478e93a802e13b5bc3fd22f4768c9b066e60 + ? ../Natural/equal.dhall + +let equal + : Integer → Integer → Bool + = λ(a : Integer) → + λ(b : Integer) → + Natural/equal (Integer/clamp a) (Integer/clamp b) + && Natural/equal + (Integer/clamp (Integer/negate a)) + (Integer/clamp (Integer/negate b)) + +let example0 = assert : equal +5 +5 ≡ True + +let example1 = assert : equal +5 +6 ≡ False + +let example2 = assert : equal +5 -5 ≡ False + +let example3 = assert : equal -5 -5 ≡ True + +in equal diff --git a/dhall/Prelude/Integer/greaterThan b/dhall/Prelude/Integer/greaterThan new file mode 100644 index 0000000..1c9b54b --- /dev/null +++ b/dhall/Prelude/Integer/greaterThan @@ -0,0 +1,3 @@ + missing + sha256:d23affd73029fc9aaf867c2c7b86510ca2802d3f0d1f3e1d1a93ffd87b7cb64b +? ./greaterThan.dhall diff --git a/dhall/Prelude/Integer/greaterThan.dhall b/dhall/Prelude/Integer/greaterThan.dhall new file mode 100644 index 0000000..c9df13f --- /dev/null +++ b/dhall/Prelude/Integer/greaterThan.dhall @@ -0,0 +1,30 @@ +--| `greaterThan` checks if one Integer is greater than another. +let Bool/not = + missing + sha256:723df402df24377d8a853afed08d9d69a0a6d86e2e5b2bac8960b0d4756c7dc4 + ? ../Bool/not.dhall + +let lessThanEqual = + missing + sha256:e3cca9f3942f81fa78a2bea23c0c24519c67cfe438116c38e797e12dcd26f6bc + ? ./lessThanEqual.dhall + +let greaterThan + : Integer → Integer → Bool + = λ(x : Integer) → λ(y : Integer) → Bool/not (lessThanEqual x y) + +let example0 = assert : greaterThan +5 +6 ≡ False + +let example1 = assert : greaterThan +5 +5 ≡ False + +let example2 = assert : greaterThan +5 +4 ≡ True + +let example3 = assert : greaterThan -5 +8 ≡ False + +let example4 = assert : greaterThan -5 -3 ≡ False + +let example5 = assert : greaterThan -3 -5 ≡ True + +let example6 = assert : greaterThan -3 -3 ≡ False + +in greaterThan diff --git a/dhall/Prelude/Integer/greaterThanEqual b/dhall/Prelude/Integer/greaterThanEqual new file mode 100644 index 0000000..2f8c326 --- /dev/null +++ b/dhall/Prelude/Integer/greaterThanEqual @@ -0,0 +1,3 @@ + missing + sha256:a9fa2dc5cd6067a23b39d7fe8d14a63109583b320429fb0e446658a5aae0a958 +? ./greaterThanEqual.dhall diff --git a/dhall/Prelude/Integer/greaterThanEqual.dhall b/dhall/Prelude/Integer/greaterThanEqual.dhall new file mode 100644 index 0000000..769df36 --- /dev/null +++ b/dhall/Prelude/Integer/greaterThanEqual.dhall @@ -0,0 +1,27 @@ +{-| +`greaterThanEqual` checks if one Integer is greater than or equal to another. +-} +let lessThanEqual = + missing + sha256:e3cca9f3942f81fa78a2bea23c0c24519c67cfe438116c38e797e12dcd26f6bc + ? ./lessThanEqual.dhall + +let greaterThanEqual + : Integer → Integer → Bool + = λ(x : Integer) → λ(y : Integer) → lessThanEqual y x + +let example0 = assert : greaterThanEqual +5 +6 ≡ False + +let example1 = assert : greaterThanEqual +5 +5 ≡ True + +let example2 = assert : greaterThanEqual +5 +4 ≡ True + +let example3 = assert : greaterThanEqual -5 +8 ≡ False + +let example4 = assert : greaterThanEqual -5 -3 ≡ False + +let example5 = assert : greaterThanEqual -3 -5 ≡ True + +let example6 = assert : greaterThanEqual -3 -3 ≡ True + +in greaterThanEqual diff --git a/dhall/Prelude/Integer/lessThan b/dhall/Prelude/Integer/lessThan new file mode 100644 index 0000000..59a90d1 --- /dev/null +++ b/dhall/Prelude/Integer/lessThan @@ -0,0 +1,3 @@ + missing + sha256:eeaa0081d10c6c97464ef193c40f1aa5cbb12f0202972ab42f3d310c2fd6a3f0 +? ./lessThan.dhall diff --git a/dhall/Prelude/Integer/lessThan.dhall b/dhall/Prelude/Integer/lessThan.dhall new file mode 100644 index 0000000..ab0e28d --- /dev/null +++ b/dhall/Prelude/Integer/lessThan.dhall @@ -0,0 +1,25 @@ +--| `lessThan` checks if one Integer is less than another. +let greaterThan = + missing + sha256:d23affd73029fc9aaf867c2c7b86510ca2802d3f0d1f3e1d1a93ffd87b7cb64b + ? ./greaterThan.dhall + +let lessThan + : Integer → Integer → Bool + = λ(x : Integer) → λ(y : Integer) → greaterThan y x + +let example0 = assert : lessThan +5 +6 ≡ True + +let example1 = assert : lessThan +5 +5 ≡ False + +let example2 = assert : lessThan +5 +4 ≡ False + +let example3 = assert : lessThan -5 +8 ≡ True + +let example4 = assert : lessThan -5 -3 ≡ True + +let example5 = assert : lessThan -3 -5 ≡ False + +let example6 = assert : lessThan -3 -3 ≡ False + +in lessThan diff --git a/dhall/Prelude/Integer/lessThanEqual b/dhall/Prelude/Integer/lessThanEqual new file mode 100644 index 0000000..0dc6fef --- /dev/null +++ b/dhall/Prelude/Integer/lessThanEqual @@ -0,0 +1,3 @@ + missing + sha256:e3cca9f3942f81fa78a2bea23c0c24519c67cfe438116c38e797e12dcd26f6bc +? ./lessThanEqual.dhall diff --git a/dhall/Prelude/Integer/lessThanEqual.dhall b/dhall/Prelude/Integer/lessThanEqual.dhall new file mode 100644 index 0000000..559edb2 --- /dev/null +++ b/dhall/Prelude/Integer/lessThanEqual.dhall @@ -0,0 +1,47 @@ +--| `lessThanEqual` checks if one Integer is less than or equal to another. +let Natural/greaterThanEqual = + missing + sha256:30ebfab0febd7aa0ccccfdf3dc36ee6d50f0117f35dd4a9b034750b7e885a1a4 + ? ../Natural/greaterThanEqual.dhall + +let Natural/lessThanEqual = + missing + sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 + ? ../Natural/lessThanEqual.dhall + +let nonPositive = + missing + sha256:e00a852eed5b84ff60487097d8aadce53c9e5301f53ff4954044bd68949fac3b + ? ./nonPositive.dhall + +let nonNegative = + missing + sha256:b463373f070df6b1c8c7082051e0810fee38b360bab35256187c8c2b6af5c663 + ? ./nonNegative.dhall + +let lessThanEqual + : Integer → Integer → Bool + = λ(x : Integer) → + λ(y : Integer) → + if nonPositive x + then nonNegative y + || Natural/greaterThanEqual + (Integer/clamp (Integer/negate x)) + (Integer/clamp (Integer/negate y)) + else Natural/lessThanEqual (Integer/clamp x) (Integer/clamp y) + +let example0 = assert : lessThanEqual +5 +6 ≡ True + +let example1 = assert : lessThanEqual +5 +5 ≡ True + +let example2 = assert : lessThanEqual +5 +4 ≡ False + +let example3 = assert : lessThanEqual -5 +8 ≡ True + +let example4 = assert : lessThanEqual -5 -3 ≡ True + +let example5 = assert : lessThanEqual -3 -5 ≡ False + +let example6 = assert : lessThanEqual -3 -3 ≡ True + +in lessThanEqual diff --git a/dhall/Prelude/Integer/multiply b/dhall/Prelude/Integer/multiply new file mode 100644 index 0000000..24548d7 --- /dev/null +++ b/dhall/Prelude/Integer/multiply @@ -0,0 +1,3 @@ + missing + sha256:dcb1ed7c8475ece8d67db92cd249fc728541778ff82509e28c3760e341880e4d +? ./multiply.dhall diff --git a/dhall/Prelude/Integer/multiply.dhall b/dhall/Prelude/Integer/multiply.dhall new file mode 100644 index 0000000..2f74980 --- /dev/null +++ b/dhall/Prelude/Integer/multiply.dhall @@ -0,0 +1,40 @@ +--| `multiply m n` computes `m * n`. +let nonPositive = + missing + sha256:e00a852eed5b84ff60487097d8aadce53c9e5301f53ff4954044bd68949fac3b + ? ./nonPositive.dhall + +let multiplyNonNegative = + λ(x : Integer) → + λ(y : Integer) → + Natural/toInteger (Integer/clamp x * Integer/clamp y) + +let multiply + : Integer → Integer → Integer + = λ(m : Integer) → + λ(n : Integer) → + if nonPositive m + then if nonPositive n + then multiplyNonNegative (Integer/negate m) (Integer/negate n) + else Integer/negate (multiplyNonNegative (Integer/negate m) n) + else if nonPositive n + then Integer/negate (multiplyNonNegative m (Integer/negate n)) + else multiplyNonNegative m n + +let example0 = assert : multiply +3 +5 ≡ +15 + +let example1 = assert : multiply -3 +5 ≡ -15 + +let example2 = assert : multiply -3 -5 ≡ +15 + +let example3 = assert : multiply +0 +5 ≡ +0 + +let example4 = assert : multiply +5 +0 ≡ +0 + +let example5 = assert : multiply +0 +0 ≡ +0 + +let example6 = assert : multiply +1 +5 ≡ +5 + +let example7 = assert : multiply +3 -1 ≡ -3 + +in multiply diff --git a/dhall/Prelude/Integer/negate b/dhall/Prelude/Integer/negate new file mode 100644 index 0000000..64a5e51 --- /dev/null +++ b/dhall/Prelude/Integer/negate @@ -0,0 +1,3 @@ + missing + sha256:2373c992e1de93634bc6a8781eb073b2a92a70170133e49762a785f3a136df5d +? ./negate.dhall diff --git a/dhall/Prelude/Integer/negate.dhall b/dhall/Prelude/Integer/negate.dhall new file mode 100644 index 0000000..03eff72 --- /dev/null +++ b/dhall/Prelude/Integer/negate.dhall @@ -0,0 +1,12 @@ +--| Invert the sign of an `Integer`, with zero remaining unchanged. +let negate + : Integer → Integer + = Integer/negate + +let example0 = assert : negate -3 ≡ +3 + +let example2 = assert : negate +7 ≡ -7 + +let example3 = assert : negate +0 ≡ +0 + +in negate diff --git a/dhall/Prelude/Integer/negative b/dhall/Prelude/Integer/negative new file mode 100644 index 0000000..a481b89 --- /dev/null +++ b/dhall/Prelude/Integer/negative @@ -0,0 +1,3 @@ + missing + sha256:23e4b3c61eea9e878a7f83bf25fd0ea2c6a6d60174890d65be885828b690a570 +? ./negative.dhall diff --git a/dhall/Prelude/Integer/negative.dhall b/dhall/Prelude/Integer/negative.dhall new file mode 100644 index 0000000..d4ca92f --- /dev/null +++ b/dhall/Prelude/Integer/negative.dhall @@ -0,0 +1,21 @@ +{-| +Returns `True` for any `Integer` less than `+0`. + +`negative` is more efficient than `./lessThan +0` or `./lessThanEqual -1`. +-} +let positive = + missing + sha256:7bdbf50fcdb83d01f74c7e2a92bf5c9104eff5d8c5b4587e9337f0caefcfdbe3 + ? ./positive.dhall + +let negative + : Integer → Bool + = λ(n : Integer) → positive (Integer/negate n) + +let example0 = assert : negative +1 ≡ False + +let example1 = assert : negative +0 ≡ False + +let example2 = assert : negative -1 ≡ True + +in negative diff --git a/dhall/Prelude/Integer/nonNegative b/dhall/Prelude/Integer/nonNegative new file mode 100644 index 0000000..235bcef --- /dev/null +++ b/dhall/Prelude/Integer/nonNegative @@ -0,0 +1,3 @@ + missing + sha256:b463373f070df6b1c8c7082051e0810fee38b360bab35256187c8c2b6af5c663 +? ./nonNegative.dhall diff --git a/dhall/Prelude/Integer/nonNegative.dhall b/dhall/Prelude/Integer/nonNegative.dhall new file mode 100644 index 0000000..60fadf8 --- /dev/null +++ b/dhall/Prelude/Integer/nonNegative.dhall @@ -0,0 +1,21 @@ +{-| +Returns `True` for `+0` and any positive `Integer`. + +`nonNegative` is more efficient than `./greaterThanEqual +0` or `./greaterThan -1`. +-} +let nonPositive = + missing + sha256:e00a852eed5b84ff60487097d8aadce53c9e5301f53ff4954044bd68949fac3b + ? ./nonPositive.dhall + +let nonNegative + : Integer → Bool + = λ(n : Integer) → nonPositive (Integer/negate n) + +let example0 = assert : nonNegative +1 ≡ True + +let example1 = assert : nonNegative +0 ≡ True + +let example2 = assert : nonNegative -1 ≡ False + +in nonNegative diff --git a/dhall/Prelude/Integer/nonPositive b/dhall/Prelude/Integer/nonPositive new file mode 100644 index 0000000..d99b88d --- /dev/null +++ b/dhall/Prelude/Integer/nonPositive @@ -0,0 +1,3 @@ + missing + sha256:e00a852eed5b84ff60487097d8aadce53c9e5301f53ff4954044bd68949fac3b +? ./nonPositive.dhall diff --git a/dhall/Prelude/Integer/nonPositive.dhall b/dhall/Prelude/Integer/nonPositive.dhall new file mode 100644 index 0000000..f7d7a49 --- /dev/null +++ b/dhall/Prelude/Integer/nonPositive.dhall @@ -0,0 +1,16 @@ +{-| +Returns `True` for `+0` and any negative `Integer`. + +`nonPositive` is more efficient than `./lessThanEqual +0` or `./lessThan +1`. +-} +let nonPositive + : Integer → Bool + = λ(n : Integer) → Natural/isZero (Integer/clamp n) + +let example0 = assert : nonPositive +1 ≡ False + +let example1 = assert : nonPositive +0 ≡ True + +let example2 = assert : nonPositive -1 ≡ True + +in nonPositive diff --git a/dhall/Prelude/Integer/package.dhall b/dhall/Prelude/Integer/package.dhall new file mode 100644 index 0000000..e19c174 --- /dev/null +++ b/dhall/Prelude/Integer/package.dhall @@ -0,0 +1,73 @@ +{ abs = + missing + sha256:35212fcbe1e60cb95b033a4a9c6e45befca4a298aa9919915999d09e69ddced1 + ? ./abs.dhall +, add = + missing + sha256:7da1306a0bf87c5668beead2a1db1b18861e53d7ce1f38057b2964b649f59c3b + ? ./add.dhall +, clamp = + missing + sha256:ea42096cf3e024fadfaf910e0b839005b0ea7514fff11e5a3950a77694d9c5d2 + ? ./clamp.dhall +, equal = + missing + sha256:2d99a205086aa77eea17ae1dab22c275f3eb007bccdc8d9895b93497ebfc39f8 + ? ./equal.dhall +, greaterThan = + missing + sha256:d23affd73029fc9aaf867c2c7b86510ca2802d3f0d1f3e1d1a93ffd87b7cb64b + ? ./greaterThan.dhall +, greaterThanEqual = + missing + sha256:a9fa2dc5cd6067a23b39d7fe8d14a63109583b320429fb0e446658a5aae0a958 + ? ./greaterThanEqual.dhall +, lessThan = + missing + sha256:eeaa0081d10c6c97464ef193c40f1aa5cbb12f0202972ab42f3d310c2fd6a3f0 + ? ./lessThan.dhall +, lessThanEqual = + missing + sha256:e3cca9f3942f81fa78a2bea23c0c24519c67cfe438116c38e797e12dcd26f6bc + ? ./lessThanEqual.dhall +, multiply = + missing + sha256:dcb1ed7c8475ece8d67db92cd249fc728541778ff82509e28c3760e341880e4d + ? ./multiply.dhall +, negate = + missing + sha256:2373c992e1de93634bc6a8781eb073b2a92a70170133e49762a785f3a136df5d + ? ./negate.dhall +, negative = + missing + sha256:23e4b3c61eea9e878a7f83bf25fd0ea2c6a6d60174890d65be885828b690a570 + ? ./negative.dhall +, nonNegative = + missing + sha256:b463373f070df6b1c8c7082051e0810fee38b360bab35256187c8c2b6af5c663 + ? ./nonNegative.dhall +, nonPositive = + missing + sha256:e00a852eed5b84ff60487097d8aadce53c9e5301f53ff4954044bd68949fac3b + ? ./nonPositive.dhall +, positive = + missing + sha256:7bdbf50fcdb83d01f74c7e2a92bf5c9104eff5d8c5b4587e9337f0caefcfdbe3 + ? ./positive.dhall +, show = + missing + sha256:ecf8b0594cd5181bc45d3b7ea0d44d3ba9ad5dac6ec17bb8968beb65f4b1baa9 + ? ./show.dhall +, subtract = + missing + sha256:a34d36272fa8ae4f1ec8b56222fe8dc8a2ec55ec6538b840de0cbe207b006fda + ? ./subtract.dhall +, toDouble = + missing + sha256:77bc5d635dc4d952f37cc96f2a681d5ac503b4e8b21fc00055b1946adb5beda7 + ? ./toDouble.dhall +, toNatural = + missing + sha256:4d128730d74e7f832e53873cb5204aa91b79758be5ce4e1aa991fe1951304a0e + ? ./toNatural.dhall +} diff --git a/dhall/Prelude/Integer/positive b/dhall/Prelude/Integer/positive new file mode 100644 index 0000000..ff62242 --- /dev/null +++ b/dhall/Prelude/Integer/positive @@ -0,0 +1,3 @@ + missing + sha256:7bdbf50fcdb83d01f74c7e2a92bf5c9104eff5d8c5b4587e9337f0caefcfdbe3 +? ./positive.dhall diff --git a/dhall/Prelude/Integer/positive.dhall b/dhall/Prelude/Integer/positive.dhall new file mode 100644 index 0000000..a7599cf --- /dev/null +++ b/dhall/Prelude/Integer/positive.dhall @@ -0,0 +1,26 @@ +{-| +Returns `True` for any `Integer` greater than `+0`. + +`positive` is more efficient than `./greaterThan +0` or `./greaterThanEqual +1`. +-} +let not = + missing + sha256:723df402df24377d8a853afed08d9d69a0a6d86e2e5b2bac8960b0d4756c7dc4 + ? ../Bool/not.dhall + +let nonPositive = + missing + sha256:e00a852eed5b84ff60487097d8aadce53c9e5301f53ff4954044bd68949fac3b + ? ./nonPositive.dhall + +let positive + : Integer → Bool + = λ(n : Integer) → not (nonPositive n) + +let example0 = assert : positive +1 ≡ True + +let example1 = assert : positive +0 ≡ False + +let example2 = assert : positive -1 ≡ False + +in positive diff --git a/dhall/Prelude/Integer/show b/dhall/Prelude/Integer/show new file mode 100644 index 0000000..e30b647 --- /dev/null +++ b/dhall/Prelude/Integer/show @@ -0,0 +1,3 @@ + missing + sha256:ecf8b0594cd5181bc45d3b7ea0d44d3ba9ad5dac6ec17bb8968beb65f4b1baa9 +? ./show.dhall diff --git a/dhall/Prelude/Integer/show.dhall b/dhall/Prelude/Integer/show.dhall new file mode 100644 index 0000000..33e6b5a --- /dev/null +++ b/dhall/Prelude/Integer/show.dhall @@ -0,0 +1,14 @@ +{-| +Render an `Integer` as `Text` using the same representation as Dhall source +code (i.e. a decimal number with a leading `-` sign if negative and a leading +`+` sign if non-negative) +-} +let show + : Integer → Text + = Integer/show + +let example0 = assert : show -3 ≡ "-3" + +let example1 = assert : show +0 ≡ "+0" + +in show diff --git a/dhall/Prelude/Integer/subtract b/dhall/Prelude/Integer/subtract new file mode 100644 index 0000000..a20839c --- /dev/null +++ b/dhall/Prelude/Integer/subtract @@ -0,0 +1,3 @@ + missing + sha256:a34d36272fa8ae4f1ec8b56222fe8dc8a2ec55ec6538b840de0cbe207b006fda +? ./subtract.dhall diff --git a/dhall/Prelude/Integer/subtract.dhall b/dhall/Prelude/Integer/subtract.dhall new file mode 100644 index 0000000..d37b1b4 --- /dev/null +++ b/dhall/Prelude/Integer/subtract.dhall @@ -0,0 +1,54 @@ +--| `subtract m n` computes `n - m`. +let nonPositive = + missing + sha256:e00a852eed5b84ff60487097d8aadce53c9e5301f53ff4954044bd68949fac3b + ? ./nonPositive.dhall + +let subtractNonNegative = + λ(xi : Integer) → + λ(yi : Integer) → + let xn = Integer/clamp xi + + let yn = Integer/clamp yi + + let dn = Natural/subtract xn yn + + in if Natural/isZero dn + then Integer/negate (Natural/toInteger (Natural/subtract yn xn)) + else Natural/toInteger dn + +let subtract + : Integer → Integer → Integer + = λ(m : Integer) → + λ(n : Integer) → + if nonPositive m + then if nonPositive n + then subtractNonNegative (Integer/negate n) (Integer/negate m) + else Natural/toInteger + (Integer/clamp (Integer/negate m) + Integer/clamp n) + else if nonPositive n + then Integer/negate + ( Natural/toInteger + (Integer/clamp m + Integer/clamp (Integer/negate n)) + ) + else subtractNonNegative m n + +let example0 = assert : subtract +3 +5 ≡ +2 + +let example1 = assert : subtract +4 +4 ≡ +0 + +let example2 = assert : subtract +5 +3 ≡ -2 + +let example3 = assert : subtract -3 -5 ≡ -2 + +let example4 = assert : subtract -4 -4 ≡ +0 + +let example5 = assert : subtract -5 -3 ≡ +2 + +let example6 = assert : subtract -3 +5 ≡ +8 + +let example7 = assert : subtract +3 -5 ≡ -8 + +let example8 = assert : subtract +0 -3 ≡ -3 + +in subtract diff --git a/dhall/Prelude/Integer/toDouble b/dhall/Prelude/Integer/toDouble new file mode 100644 index 0000000..ec1018f --- /dev/null +++ b/dhall/Prelude/Integer/toDouble @@ -0,0 +1,3 @@ + missing + sha256:77bc5d635dc4d952f37cc96f2a681d5ac503b4e8b21fc00055b1946adb5beda7 +? ./toDouble.dhall diff --git a/dhall/Prelude/Integer/toDouble.dhall b/dhall/Prelude/Integer/toDouble.dhall new file mode 100644 index 0000000..b5d1e61 --- /dev/null +++ b/dhall/Prelude/Integer/toDouble.dhall @@ -0,0 +1,10 @@ +--| Convert an `Integer` to the corresponding `Double` +let toDouble + : Integer → Double + = Integer/toDouble + +let example0 = assert : toDouble -3 ≡ -3.0 + +let example1 = assert : toDouble +2 ≡ 2.0 + +in toDouble diff --git a/dhall/Prelude/Integer/toNatural b/dhall/Prelude/Integer/toNatural new file mode 100644 index 0000000..9690468 --- /dev/null +++ b/dhall/Prelude/Integer/toNatural @@ -0,0 +1,3 @@ + missing + sha256:4d128730d74e7f832e53873cb5204aa91b79758be5ce4e1aa991fe1951304a0e +? ./toNatural.dhall diff --git a/dhall/Prelude/Integer/toNatural.dhall b/dhall/Prelude/Integer/toNatural.dhall new file mode 100644 index 0000000..d84e919 --- /dev/null +++ b/dhall/Prelude/Integer/toNatural.dhall @@ -0,0 +1,20 @@ +{-| +Convert an `Integer` to an `Optional Natural`, with negative numbers becoming `None Natural`. +-} +let nonNegative = + missing + sha256:b463373f070df6b1c8c7082051e0810fee38b360bab35256187c8c2b6af5c663 + ? ./nonNegative.dhall + +let toNatural + : Integer → Optional Natural + = λ(n : Integer) → + if nonNegative n then Some (Integer/clamp n) else None Natural + +let example0 = assert : toNatural +7 ≡ Some 7 + +let example2 = assert : toNatural +0 ≡ Some 0 + +let example3 = assert : toNatural -3 ≡ None Natural + +in toNatural diff --git a/dhall/Prelude/JSON/Format b/dhall/Prelude/JSON/Format new file mode 100644 index 0000000..e73c999 --- /dev/null +++ b/dhall/Prelude/JSON/Format @@ -0,0 +1,3 @@ + missing + sha256:d7936b510cfc091faa994652af0eb5feb889cd44bc989edbe4f1eb8c5623caac +? ./Format.dhall diff --git a/dhall/Prelude/JSON/Format.dhall b/dhall/Prelude/JSON/Format.dhall new file mode 100644 index 0000000..649600b --- /dev/null +++ b/dhall/Prelude/JSON/Format.dhall @@ -0,0 +1,7 @@ +{-| +An internal type used by `./renderAs` to select the output format. + +You should not need to use this type directly, simply use `./render` +or `./renderYAML` as appropriate. +-} +< YAML | JSON > diff --git a/dhall/Prelude/JSON/Nesting b/dhall/Prelude/JSON/Nesting new file mode 100644 index 0000000..1cc0d0d --- /dev/null +++ b/dhall/Prelude/JSON/Nesting @@ -0,0 +1,3 @@ + missing + sha256:6284802edd41d5d725aa1ec7687e614e21ad1be7e14dd10996bfa9625105c335 +? ./Nesting.dhall diff --git a/dhall/Prelude/JSON/Nesting.dhall b/dhall/Prelude/JSON/Nesting.dhall new file mode 100644 index 0000000..b371f73 --- /dev/null +++ b/dhall/Prelude/JSON/Nesting.dhall @@ -0,0 +1,35 @@ +{-| +This type is used as part of `dhall-json`'s support for preserving alternative +names + +For example, this Dhall code: + +``` +let Example = < Left : { foo : Natural } | Right : { bar : Bool } > + +let Nesting = < Inline | Nested : Text > + +in { field = + "name" + , nesting = + Nesting.Inline + , contents = + Example.Left { foo = 2 } + } +``` + +... generates this JSON: + +``` +{ + "foo": 2, + "name": "Left" +} +``` + +-} +let Nesting + : Type + = < Inline | Nested : Text > + +in Nesting diff --git a/dhall/Prelude/JSON/Tagged b/dhall/Prelude/JSON/Tagged new file mode 100644 index 0000000..4cf5d5e --- /dev/null +++ b/dhall/Prelude/JSON/Tagged @@ -0,0 +1,3 @@ + missing + sha256:21feca7d2b23f210d0696131d792e18a7d24fdcc85d41a49ba85b98670eba194 +? ./Tagged.dhall diff --git a/dhall/Prelude/JSON/Tagged.dhall b/dhall/Prelude/JSON/Tagged.dhall new file mode 100644 index 0000000..9ffed4e --- /dev/null +++ b/dhall/Prelude/JSON/Tagged.dhall @@ -0,0 +1,74 @@ +{-| +This is a convenient type-level function when using `dhall-to-json`'s support +for preserving alternative names + +For example, this code: + +``` +let map = ../List/map + +let Provisioner = + < shell : + { inline : List Text } + | file : + { source : Text, destination : Text } + > + +let Tagged = ./Tagged + +let Nesting = ./Nesting + +let wrap + : Provisioner → Tagged Provisioner + = λ(x : Provisioner) → + { field = "type", nesting = Nesting.Nested "params", contents = x } + +in { provisioners = + map + Provisioner + (Tagged Provisioner) + wrap + [ Provisioner.shell { inline = [ "echo foo" ] } + , Provisioner.file + { source = "app.tar.gz", destination = "/tmp/app.tar.gz" } + ] + } +``` + +... produces this JSON: + +``` +{ + "provisioners": [ + { + "params": { + "inline": [ + "echo foo" + ] + }, + "type": "shell" + }, + { + "params": { + "destination": "/tmp/app.tar.gz", + "source": "app.tar.gz" + }, + "type": "file" + } + ] +} +``` + +-} +let Tagged + : Type → Type + = λ(a : Type) → + { field : Text + , nesting : + missing + sha256:6284802edd41d5d725aa1ec7687e614e21ad1be7e14dd10996bfa9625105c335 + ? ./Nesting.dhall + , contents : a + } + +in Tagged diff --git a/dhall/Prelude/JSON/Type b/dhall/Prelude/JSON/Type new file mode 100644 index 0000000..57963f2 --- /dev/null +++ b/dhall/Prelude/JSON/Type @@ -0,0 +1,3 @@ + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 +? ./Type.dhall diff --git a/dhall/Prelude/JSON/Type.dhall b/dhall/Prelude/JSON/Type.dhall new file mode 100644 index 0000000..83caf24 --- /dev/null +++ b/dhall/Prelude/JSON/Type.dhall @@ -0,0 +1,63 @@ +{-| +Dhall encoding of an arbitrary JSON value + +For example, the following JSON value: + +``` +[ { "foo": null, "bar": [ 1.0, true ] } ] +``` + +... corresponds to the following Dhall expression: + +``` +λ(JSON : Type) → +λ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , null : JSON + , double : Double → JSON + , integer : Integer → JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + json.object + [ { mapKey = "foo", mapValue = json.null } + , { mapKey = "bar" + , mapValue = json.array [ json.double 1.0, json.bool True ] + } + ] +``` + + You do not need to create these values directly, though. You can use + the utilities exported by `./package.dhall` to create values of this type, + such as: + +``` +let JSON = ./package.dhall + +in JSON.object + [ { mapKey = "foo", mapValue = JSON.null } + , { mapKey = "bar" + , mapValue = JSON.array [ JSON.double 1.0, JSON.bool True ] + } + ] +``` + +-} +let JSON/Type + : Type + = ∀(JSON : Type) → + ∀ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , double : Double → JSON + , integer : Integer → JSON + , null : JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + JSON + +in JSON/Type diff --git a/dhall/Prelude/JSON/array b/dhall/Prelude/JSON/array new file mode 100644 index 0000000..2ec8783 --- /dev/null +++ b/dhall/Prelude/JSON/array @@ -0,0 +1,3 @@ + missing + sha256:fb6346a9c63638fe3c59f8108e19eebdbddc51389ec5570bab4c25f890ccccc8 +? ./array.dhall diff --git a/dhall/Prelude/JSON/array.dhall b/dhall/Prelude/JSON/array.dhall new file mode 100644 index 0000000..4e8549b --- /dev/null +++ b/dhall/Prelude/JSON/array.dhall @@ -0,0 +1,41 @@ +{-| +Create a JSON array from a `List` of JSON values + +``` +let JSON = ./package.dhall +in JSON.render (JSON.array [ JSON.double 1.0, JSON.bool True ]) += "[ 1.0, true ]" + +let JSON/Type = ./Type +let JSON = ./package.dhall +in JSON.render (JSON.array ([] : List JSON/Type)) += "[ ]" +``` +-} +let JSON = + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 + ? ./Type.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map.dhall + +let array + : List JSON → JSON + = λ(x : List JSON) → + λ(JSON : Type) → + λ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , double : Double → JSON + , integer : Integer → JSON + , null : JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + json.array (List/map JSON@1 JSON (λ(j : JSON@1) → j JSON json) x) + +in array diff --git a/dhall/Prelude/JSON/bool b/dhall/Prelude/JSON/bool new file mode 100644 index 0000000..845aea3 --- /dev/null +++ b/dhall/Prelude/JSON/bool @@ -0,0 +1,3 @@ + missing + sha256:e043d9ed01e5b45899059e128243f3dae7ce65f293f0015ce816fc36d30f7f39 +? ./bool.dhall diff --git a/dhall/Prelude/JSON/bool.dhall b/dhall/Prelude/JSON/bool.dhall new file mode 100644 index 0000000..bc9cba1 --- /dev/null +++ b/dhall/Prelude/JSON/bool.dhall @@ -0,0 +1,35 @@ +{-| +Create a JSON bool from a Dhall `Bool` + +``` +let JSON = ./package.dhall +in JSON.render (JSON.bool True) += "true" + +let JSON = ./package.dhall +in JSON.render (JSON.bool False) += "false" +``` +-} +let JSON = + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 + ? ./Type.dhall + +let bool + : Bool → JSON + = λ(x : Bool) → + λ(JSON : Type) → + λ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , double : Double → JSON + , integer : Integer → JSON + , null : JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + json.bool x + +in bool diff --git a/dhall/Prelude/JSON/core.dhall b/dhall/Prelude/JSON/core.dhall new file mode 100644 index 0000000..30ee288 --- /dev/null +++ b/dhall/Prelude/JSON/core.dhall @@ -0,0 +1,70 @@ +{-| +A record of functions useful for constructing `JSON` values. + +This is only a subset of what `package.dhall` exports. If you are not writing a +JSON prelude function, you should use the `package.dhall` file instead. + +It is used internally by `render`, `renderYAML` and `omitNullFields` instead of +`package.dhall` to avoid import cycles. +-} +{ Type = + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 + ? ./Type.dhall +, Tagged = + missing + sha256:21feca7d2b23f210d0696131d792e18a7d24fdcc85d41a49ba85b98670eba194 + ? ./Tagged.dhall +, Nesting = + missing + sha256:6284802edd41d5d725aa1ec7687e614e21ad1be7e14dd10996bfa9625105c335 + ? ./Nesting.dhall +, keyText = + missing + sha256:f7b6c802ca5764d03d5e9a6e48d9cb167c01392f775d9c2c87b83cdaa60ea0cc + ? ./keyText.dhall +, keyValue = + missing + sha256:a0a97199d280c4cce72ffcbbf93b7ceda0a569cf4d173ac98e0aaaa78034b98c + ? ./keyValue.dhall +, string = + missing + sha256:7ddb3a3b9f3ed09ed011d621a10ad9825185cd03503be98a81d42f6afb77940e + ? ./string.dhall +, number = + missing + sha256:e70162c73c4978ad0d0d99505f61c7d990f3abadfcc08b34388b29c0934a7a32 + ? ./number.dhall +, double = + missing + sha256:e70162c73c4978ad0d0d99505f61c7d990f3abadfcc08b34388b29c0934a7a32 + ? ./double.dhall +, integer = + missing + sha256:c81a417397fc6f62155ec71fdd8d2047f981f0881295b307de3dd88747bf7e40 + ? ./integer.dhall +, natural = + missing + sha256:a839dc6789f19f820e9cbf70c60f41f3b057c59ece1d226d04db5aca447eb0e5 + ? ./natural.dhall +, object = + missing + sha256:869aede785c34798be9f9fd457ece73e7f683f352ae4555f791516a365faf4ac + ? ./object.dhall +, array = + missing + sha256:fb6346a9c63638fe3c59f8108e19eebdbddc51389ec5570bab4c25f890ccccc8 + ? ./array.dhall +, bool = + missing + sha256:e043d9ed01e5b45899059e128243f3dae7ce65f293f0015ce816fc36d30f7f39 + ? ./bool.dhall +, null = + missing + sha256:1eeb9aee38eb8dde0e64efbaf60f24612c8194cc00b510bfb627c2ee2e1877b8 + ? ./null.dhall +, renderInteger = + missing + sha256:15b8d2ae46d5002832741927af787761df49798c911e2bf85db7a7b9cb5c078c + ? ./renderInteger.dhall +} diff --git a/dhall/Prelude/JSON/double b/dhall/Prelude/JSON/double new file mode 100644 index 0000000..de87d83 --- /dev/null +++ b/dhall/Prelude/JSON/double @@ -0,0 +1,3 @@ + missing + sha256:e70162c73c4978ad0d0d99505f61c7d990f3abadfcc08b34388b29c0934a7a32 +? ./double.dhall diff --git a/dhall/Prelude/JSON/double.dhall b/dhall/Prelude/JSON/double.dhall new file mode 100644 index 0000000..49498c6 --- /dev/null +++ b/dhall/Prelude/JSON/double.dhall @@ -0,0 +1,35 @@ +{-| +Create a JSON number from a Dhall `Double` + +``` +let JSON = ./package.dhall +in JSON.render (JSON.double 42.0) += "42.0" + +let JSON = ./package.dhall +in JSON.render (JSON.double -1.5e-10) += "-1.5e-10" +``` +-} +let JSON = + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 + ? ./Type.dhall + +let double + : Double → JSON + = λ(x : Double) → + λ(JSON : Type) → + λ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , double : Double → JSON + , integer : Integer → JSON + , null : JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + json.double x + +in double diff --git a/dhall/Prelude/JSON/integer b/dhall/Prelude/JSON/integer new file mode 100644 index 0000000..a168656 --- /dev/null +++ b/dhall/Prelude/JSON/integer @@ -0,0 +1,3 @@ + missing + sha256:c81a417397fc6f62155ec71fdd8d2047f981f0881295b307de3dd88747bf7e40 +? ./integer.dhall diff --git a/dhall/Prelude/JSON/integer.dhall b/dhall/Prelude/JSON/integer.dhall new file mode 100644 index 0000000..762b9e1 --- /dev/null +++ b/dhall/Prelude/JSON/integer.dhall @@ -0,0 +1,35 @@ +{-| +Create a JSON number from a Dhall `Integer` + +``` +let JSON = ./package.dhall +in JSON.render (JSON.integer -1) += "-1" + +let JSON = ./package.dhall +in JSON.render (JSON.integer +2) += "+2" +``` +-} +let JSON = + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 + ? ./Type.dhall + +let integer + : Integer → JSON + = λ(x : Integer) → + λ(JSON : Type) → + λ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , double : Double → JSON + , integer : Integer → JSON + , null : JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + json.integer x + +in integer diff --git a/dhall/Prelude/JSON/keyText b/dhall/Prelude/JSON/keyText new file mode 100644 index 0000000..8710683 --- /dev/null +++ b/dhall/Prelude/JSON/keyText @@ -0,0 +1,3 @@ + missing + sha256:f7b6c802ca5764d03d5e9a6e48d9cb167c01392f775d9c2c87b83cdaa60ea0cc +? ./keyText.dhall diff --git a/dhall/Prelude/JSON/keyText.dhall b/dhall/Prelude/JSON/keyText.dhall new file mode 100644 index 0000000..c354128 --- /dev/null +++ b/dhall/Prelude/JSON/keyText.dhall @@ -0,0 +1,3 @@ + missing + sha256:f7b6c802ca5764d03d5e9a6e48d9cb167c01392f775d9c2c87b83cdaa60ea0cc +? ../Map/keyText.dhall diff --git a/dhall/Prelude/JSON/keyValue b/dhall/Prelude/JSON/keyValue new file mode 100644 index 0000000..d762d37 --- /dev/null +++ b/dhall/Prelude/JSON/keyValue @@ -0,0 +1,3 @@ + missing + sha256:a0a97199d280c4cce72ffcbbf93b7ceda0a569cf4d173ac98e0aaaa78034b98c +? ./keyValue.dhall diff --git a/dhall/Prelude/JSON/keyValue.dhall b/dhall/Prelude/JSON/keyValue.dhall new file mode 100644 index 0000000..6de244d --- /dev/null +++ b/dhall/Prelude/JSON/keyValue.dhall @@ -0,0 +1,3 @@ + missing + sha256:a0a97199d280c4cce72ffcbbf93b7ceda0a569cf4d173ac98e0aaaa78034b98c +? ../Map/keyValue.dhall diff --git a/dhall/Prelude/JSON/natural b/dhall/Prelude/JSON/natural new file mode 100644 index 0000000..9834a80 --- /dev/null +++ b/dhall/Prelude/JSON/natural @@ -0,0 +1,3 @@ + missing + sha256:a839dc6789f19f820e9cbf70c60f41f3b057c59ece1d226d04db5aca447eb0e5 +? ./natural.dhall diff --git a/dhall/Prelude/JSON/natural.dhall b/dhall/Prelude/JSON/natural.dhall new file mode 100644 index 0000000..11588c5 --- /dev/null +++ b/dhall/Prelude/JSON/natural.dhall @@ -0,0 +1,31 @@ +{-| +Create a JSON number from a Dhall `Natural` + +``` +let JSON = ./package.dhall +in JSON.render (JSON.natural 42) += "42" +``` +-} +let JSON = + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 + ? ./Type.dhall + +let natural + : Natural → JSON + = λ(x : Natural) → + λ(JSON : Type) → + λ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , double : Double → JSON + , integer : Integer → JSON + , null : JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + json.integer (Natural/toInteger x) + +in natural diff --git a/dhall/Prelude/JSON/null b/dhall/Prelude/JSON/null new file mode 100644 index 0000000..d55eb2f --- /dev/null +++ b/dhall/Prelude/JSON/null @@ -0,0 +1,3 @@ + missing + sha256:1eeb9aee38eb8dde0e64efbaf60f24612c8194cc00b510bfb627c2ee2e1877b8 +? ./null.dhall diff --git a/dhall/Prelude/JSON/null.dhall b/dhall/Prelude/JSON/null.dhall new file mode 100644 index 0000000..a1b6f78 --- /dev/null +++ b/dhall/Prelude/JSON/null.dhall @@ -0,0 +1,30 @@ +{-| +Create a JSON null + +``` +let JSON = ./package.dhall +in JSON.render JSON.null += "null" +``` +-} +let JSON = + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 + ? ./Type.dhall + +let null + : JSON + = λ(JSON : Type) → + λ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , double : Double → JSON + , integer : Integer → JSON + , null : JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + json.null + +in null diff --git a/dhall/Prelude/JSON/number b/dhall/Prelude/JSON/number new file mode 100644 index 0000000..7b48d34 --- /dev/null +++ b/dhall/Prelude/JSON/number @@ -0,0 +1,3 @@ + missing + sha256:e70162c73c4978ad0d0d99505f61c7d990f3abadfcc08b34388b29c0934a7a32 +? ./number.dhall diff --git a/dhall/Prelude/JSON/number.dhall b/dhall/Prelude/JSON/number.dhall new file mode 100644 index 0000000..0cfdc6d --- /dev/null +++ b/dhall/Prelude/JSON/number.dhall @@ -0,0 +1,28 @@ +{-| +Create a JSON number from a Dhall `Double` + +``` +let JSON = ./package.dhall +in JSON.render (JSON.number 42.0) += "42.0" + +let JSON = ./package.dhall +in JSON.render (JSON.number -1.5e-10) += "-1.5e-10" +``` +-} +let JSON = + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 + ? ./Type.dhall + +let double = + missing + sha256:e70162c73c4978ad0d0d99505f61c7d990f3abadfcc08b34388b29c0934a7a32 + ? ./double.dhall + +let number + : Double → JSON + = double + +in number diff --git a/dhall/Prelude/JSON/object b/dhall/Prelude/JSON/object new file mode 100644 index 0000000..afdd949 --- /dev/null +++ b/dhall/Prelude/JSON/object @@ -0,0 +1,3 @@ + missing + sha256:869aede785c34798be9f9fd457ece73e7f683f352ae4555f791516a365faf4ac +? ./object.dhall diff --git a/dhall/Prelude/JSON/object.dhall b/dhall/Prelude/JSON/object.dhall new file mode 100644 index 0000000..6976c8f --- /dev/null +++ b/dhall/Prelude/JSON/object.dhall @@ -0,0 +1,55 @@ +{-| +Create a JSON object from a Dhall `Map` + +``` +let JSON = ./package.dhall +in JSON.render + ( JSON.object + [ { mapKey = "foo", mapValue = JSON.double 1.0 } + , { mapKey = "bar", mapValue = JSON.bool True } + ] + ) += "{ \"foo\": 1.0, \"bar\": true }" + +let JSON/Type = ./Type +let JSON = ./package.dhall +in JSON.render + (JSON.object ([] : List { mapKey : Text, mapValue : JSON/Type })) += "{ }" +``` +-} +let JSON = + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 + ? ./Type.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map.dhall + +let object + : List { mapKey : Text, mapValue : JSON } → JSON + = λ(x : List { mapKey : Text, mapValue : JSON }) → + λ(JSON : Type) → + λ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , double : Double → JSON + , integer : Integer → JSON + , null : JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + json.object + ( List/map + { mapKey : Text, mapValue : JSON@1 } + { mapKey : Text, mapValue : JSON } + ( λ(kv : { mapKey : Text, mapValue : JSON@1 }) → + { mapKey = kv.mapKey, mapValue = kv.mapValue JSON json } + ) + x + ) + +in object diff --git a/dhall/Prelude/JSON/omitNullFields b/dhall/Prelude/JSON/omitNullFields new file mode 100644 index 0000000..ce140bc --- /dev/null +++ b/dhall/Prelude/JSON/omitNullFields @@ -0,0 +1,3 @@ + missing + sha256:e6850e70094540b75edeb46f4d6038324a62def8d63544a1e9541f79739db6f0 +? ./omitNullFields.dhall diff --git a/dhall/Prelude/JSON/omitNullFields.dhall b/dhall/Prelude/JSON/omitNullFields.dhall new file mode 100644 index 0000000..a1d1248 --- /dev/null +++ b/dhall/Prelude/JSON/omitNullFields.dhall @@ -0,0 +1,145 @@ +{-| +This utility omits all `null` record fields, which is often the idiomatic way +for a configuration to encode absent fields +-} +let JSON = + missing + sha256:5dc1135d5481cfd6fde625aaed9fcbdb7aa7c14f2e76726aa5fdef028a5c10f5 + ? ./core.dhall + +let List/concatMap = + missing + sha256:3b2167061d11fda1e4f6de0522cbe83e0d5ac4ef5ddf6bb0b2064470c5d3fb64 + ? ../List/concatMap.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map.dhall + +let omitNullFields + : JSON.Type → JSON.Type + = λ(old : JSON.Type) → + λ(JSON : Type) → + λ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , double : Double → JSON + , integer : Integer → JSON + , null : JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + let result = + old + { value : JSON, isNull : Bool } + { string = + λ(x : Text) → { value = json.string x, isNull = False } + , double = + λ(x : Double) → { value = json.double x, isNull = False } + , integer = + λ(x : Integer) → { value = json.integer x, isNull = False } + , object = + λ ( keyValues + : List + { mapKey : Text + , mapValue : { value : JSON, isNull : Bool } + } + ) → + let value = + json.object + ( List/concatMap + { mapKey : Text + , mapValue : { value : JSON, isNull : Bool } + } + { mapKey : Text, mapValue : JSON } + ( λ ( keyValue + : { mapKey : Text + , mapValue : + { value : JSON, isNull : Bool } + } + ) → + if keyValue.mapValue.isNull + then [] : List + { mapKey : Text + , mapValue : JSON + } + else [ keyValue.{ mapKey } + ∧ { mapValue = + keyValue.mapValue.value + } + ] + ) + keyValues + ) + + in { value, isNull = False } + , array = + λ(xs : List { value : JSON, isNull : Bool }) → + let value = + json.array + ( List/map + { value : JSON, isNull : Bool } + JSON + ( λ(x : { value : JSON, isNull : Bool }) → + x.value + ) + xs + ) + + in { value, isNull = False } + , bool = λ(x : Bool) → { value = json.bool x, isNull = False } + , null = { value = json.null, isNull = True } + } + + in result.value + +let property = + λ(a : Text) → + λ(b : Double) → + λ(c : Bool) → + assert + : omitNullFields + ( JSON.object + ( toMap + { string = JSON.string a + , double = JSON.double b + , bool = JSON.bool c + , null = JSON.null + } + ) + ) + ≡ JSON.object + ( toMap + { string = JSON.string a + , double = JSON.double b + , bool = JSON.bool c + } + ) + +let example = + assert + : omitNullFields + ( JSON.object + ( toMap + { array = + JSON.array [ JSON.object (toMap { null = JSON.null }) ] + } + ) + ) + ≡ JSON.object + ( toMap + { array = + JSON.array + [ JSON.object + ([] : List { mapKey : Text, mapValue : JSON.Type }) + ] + } + ) + +let example = + assert + : omitNullFields (JSON.array [ JSON.null ]) ≡ JSON.array [ JSON.null ] + +in omitNullFields diff --git a/dhall/Prelude/JSON/package.dhall b/dhall/Prelude/JSON/package.dhall new file mode 100644 index 0000000..b607fe0 --- /dev/null +++ b/dhall/Prelude/JSON/package.dhall @@ -0,0 +1,29 @@ + { render = + missing + sha256:36befdd8bb5a1c2b372709da245a8d074533b86429e137b894c08ad16fa34836 + ? ./render.dhall + , renderCompact = + missing + sha256:e6c8809fbe193fddd430f94350d69cefd45e7aaf8bd379e51b750fde75008562 + ? ./renderCompact.dhall + , renderYAML = + missing + sha256:bc71449397bbf48103c3ebbdd570cd27313115e94b2b1b96761d257d5c02d478 + ? ./renderYAML.dhall + , omitNullFields = + missing + sha256:e6850e70094540b75edeb46f4d6038324a62def8d63544a1e9541f79739db6f0 + ? ./omitNullFields.dhall + , tagInline = + missing + sha256:49559ac11906ba6cc9eac25753e31e7addb13bc760df108024174c55523984c4 + ? ./tagInline.dhall + , tagNested = + missing + sha256:93a7415853b7677c832246efadc8e880c1b641a23589286a836a384ca311d26f + ? ./tagNested.dhall + } +∧ ( missing + sha256:5dc1135d5481cfd6fde625aaed9fcbdb7aa7c14f2e76726aa5fdef028a5c10f5 + ? ./core.dhall + ) diff --git a/dhall/Prelude/JSON/render b/dhall/Prelude/JSON/render new file mode 100644 index 0000000..3d2fb62 --- /dev/null +++ b/dhall/Prelude/JSON/render @@ -0,0 +1,3 @@ + missing + sha256:36befdd8bb5a1c2b372709da245a8d074533b86429e137b894c08ad16fa34836 +? ./render.dhall diff --git a/dhall/Prelude/JSON/render.dhall b/dhall/Prelude/JSON/render.dhall new file mode 100644 index 0000000..37d953c --- /dev/null +++ b/dhall/Prelude/JSON/render.dhall @@ -0,0 +1,52 @@ +{-| +Render a `JSON` value as `Text` + +This is useful for debugging `JSON` values or for tests. For anything +more sophisticated you should use `dhall-to-json` or `dhall-to-yaml` +-} +let JSON = + missing + sha256:5dc1135d5481cfd6fde625aaed9fcbdb7aa7c14f2e76726aa5fdef028a5c10f5 + ? ./core.dhall + +let renderAs = + missing + sha256:c23be039c9601a33d6546fd99a8d72bee8dde5f46176d57cc96613b31a3bb471 + ? ./renderAs.dhall + +let Format = + missing + sha256:d7936b510cfc091faa994652af0eb5feb889cd44bc989edbe4f1eb8c5623caac + ? ./Format.dhall + +let render + : JSON.Type → Text + = renderAs Format.JSON + +let example0 = + let data = + assert + : render + ( JSON.array + [ JSON.bool True + , JSON.string "Hello" + , JSON.object + [ { mapKey = "foo", mapValue = JSON.null } + , { mapKey = "bar", mapValue = JSON.double 1.0 } + ] + ] + ) + ≡ '' + [ + true, + "Hello", + { + "foo": null, + "bar": 1.0 + } + ] + '' + + in True + +in render diff --git a/dhall/Prelude/JSON/renderAs b/dhall/Prelude/JSON/renderAs new file mode 100644 index 0000000..518f720 --- /dev/null +++ b/dhall/Prelude/JSON/renderAs @@ -0,0 +1,3 @@ + missing + sha256:c23be039c9601a33d6546fd99a8d72bee8dde5f46176d57cc96613b31a3bb471 +? ./renderAs.dhall diff --git a/dhall/Prelude/JSON/renderAs.dhall b/dhall/Prelude/JSON/renderAs.dhall new file mode 100644 index 0000000..d65ab1a --- /dev/null +++ b/dhall/Prelude/JSON/renderAs.dhall @@ -0,0 +1,458 @@ +--| Render a `JSON` value as `Text` in either JSON or YAML format. +let JSON = + missing + sha256:5dc1135d5481cfd6fde625aaed9fcbdb7aa7c14f2e76726aa5fdef028a5c10f5 + ? ./core.dhall + +let Function/identity = + missing + sha256:f78b96792b459cb664f41c6119bd8897dd04353a3343521d436cd82ad71cb4d4 + ? ../Function/identity.dhall + +let Text/concatMap = + missing + sha256:7a0b0b99643de69d6f94ba49441cd0fa0507cbdfa8ace0295f16097af37e226f + ? ../Text/concatMap.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map.dhall + +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ../NonEmpty/Type.dhall + +let NonEmpty/toList = + missing + sha256:0977fe14b77232a4451dcf409c43df4589c4b3cdde7b613aab8df183be1b53f5 + ? ../NonEmpty/toList.dhall + +let NonEmpty/concat = + missing + sha256:6d55181938c06c6b806877028f6a241912e9c0935d9a10dd958775bf21e0f64d + ? ../NonEmpty/concat.dhall + +let NonEmpty/map = + missing + sha256:93d53afe874bb2eed946c21ca5ada3c9716b7d00e6d8edfaba6484cd9c5a00bd + ? ../NonEmpty/map.dhall + +let NonEmpty/singleton = + missing + sha256:c9197aabe97695f7ca66f7419bf172d806b2c915594a8fc0d2ff6495db496ff2 + ? ../NonEmpty/singleton.dhall + +let List/uncons + : ∀(a : Type) → List a → Optional (NonEmpty a) + = {- This version uses the `ls` argument only once to prevent cache blowups at the price + of performing two passes over the list: + A first one to reverse it, a second one with `List/fold` to determine + the head element. + See https://github.com/dhall-lang/dhall-lang/pull/1015#issuecomment-633381024 + for some context regarding the caching issue. + -} + λ(a : Type) → + λ(ls : List a) → + List/fold + a + (List/reverse a ls) + (Optional (NonEmpty a)) + ( λ(x : a) → + λ(acc : Optional (NonEmpty a)) → + merge + { None = Some (NonEmpty/singleton a x) + , Some = + λ(ne : NonEmpty a) → Some (ne ⫽ { tail = ne.tail # [ x ] }) + } + acc + ) + (None (NonEmpty a)) + +let NonEmpty/mapHead + : ∀(a : Type) → (a → a) → NonEmpty a → NonEmpty a + = λ(a : Type) → + λ(fn : a → a) → + λ(ls : NonEmpty a) → + ls ⫽ { head = fn ls.head } + +let NonEmpty/mapTail + : ∀(a : Type) → (a → a) → NonEmpty a → NonEmpty a + = λ(a : Type) → + λ(fn : a → a) → + λ(ls : NonEmpty a) → + ls ⫽ { tail = List/map a a fn ls.tail } + +let NonEmpty/prepend + : ∀(a : Type) → a → NonEmpty a → NonEmpty a + = λ(a : Type) → + λ(prefix : a) → + λ(ls : NonEmpty a) → + { head = prefix, tail = NonEmpty/toList a ls } + +let NonYtpme + : Type → Type + = λ(a : Type) → { init : List a, last : a } + +let List/unsnoc + : ∀(a : Type) → List a → Optional (NonYtpme a) + = λ(a : Type) → + λ(ls : List a) → + List/fold + a + ls + (Optional (NonYtpme a)) + ( λ(x : a) → + λ(acc : Optional (NonYtpme a)) → + merge + { None = Some { init = [] : List a, last = x } + , Some = + λ(ny : NonYtpme a) → Some (ny ⫽ { init = [ x ] # ny.init }) + } + acc + ) + (None (NonYtpme a)) + +let NonEmpty/mapLast + : ∀(a : Type) → (a → a) → NonEmpty a → NonEmpty a + = λ(a : Type) → + λ(fn : a → a) → + λ(ls : NonEmpty a) → + merge + { Some = λ(x : NonYtpme a) → ls ⫽ { tail = x.init # [ fn x.last ] } + , None = NonEmpty/singleton a (fn ls.head) + } + (List/unsnoc a ls.tail) + +let NonEmpty/mapLeading + : ∀(a : Type) → (a → a) → NonEmpty a → NonEmpty a + = λ(a : Type) → + λ(fn : a → a) → + λ(ls : NonEmpty a) → + merge + { Some = + λ(x : NonYtpme a) → + { head = fn ls.head + , tail = List/map a a fn x.init # [ x.last ] + } + , None = ls + } + (List/unsnoc a ls.tail) + +let Lines + : Type + = NonEmpty Text + +let Block + : Type + = < Simple : Text | Complex : Lines > + +let Block/toLines + : Block → Lines + = λ(block : Block) → + merge + { Simple = NonEmpty/singleton Text + , Complex = Function/identity Lines + } + block + +let manyBlocks + : ∀(a : Type) → Text → (NonEmpty a → Lines) → List a → Block + = λ(a : Type) → + λ(ifEmpty : Text) → + λ(render : NonEmpty a → Lines) → + λ(inputs : List a) → + merge + { Some = λ(inputs : NonEmpty a) → Block.Complex (render inputs) + , None = Block.Simple ifEmpty + } + (List/uncons a inputs) + +let blockToText + : Block → Text + = λ(block : Block) → + Text/concatMap + Text + (λ(line : Text) → line ++ "\n") + (NonEmpty/toList Text (Block/toLines block)) + +let addPrefix = λ(prefix : Text) → λ(line : Text) → prefix ++ line + +let addIndent = addPrefix " " + +let indentTail = NonEmpty/mapTail Text addIndent + +let Format = + missing + sha256:d7936b510cfc091faa994652af0eb5feb889cd44bc989edbe4f1eb8c5623caac + ? ./Format.dhall + +let ObjectField = { mapKey : Text, mapValue : Block } + +let -- Essentially the same thing as `Text/show`, except that this does not + -- escape `$` + escape = + List/fold + (Text → Text) + [ Text/replace "\"" "\\\"" + , Text/replace "\b" "\\b" + , Text/replace "\f" "\\f" + , Text/replace "\n" "\\n" + , Text/replace "\r" "\\r" + , Text/replace "\t" "\\t" + , Text/replace "\\" "\\\\" + ] + Text + (λ(replace : Text → Text) → λ(text : Text) → replace text) + +let renderJSONStruct = + λ(prefix : Text) → + λ(suffix : Text) → + λ(blocks : NonEmpty Lines) → + let indent = List/map Text Text addIndent + + let appendComma + : Lines → Lines + = NonEmpty/mapLast Text (λ(line : Text) → line ++ ",") + + let blocks = NonEmpty/mapLeading Lines appendComma blocks + + let block = NonEmpty/concat Text blocks + + in merge + { None = + NonEmpty/singleton Text "${prefix} ${block.head} ${suffix}" + , Some = + λ(ny : NonYtpme Text) → + { head = prefix + , tail = + indent ([ block.head ] # ny.init # [ ny.last ]) + # [ suffix ] + } + } + (List/unsnoc Text block.tail) + +let renderObject = + λ(format : Format) → + λ(fields : NonEmpty ObjectField) → + let keystr = λ(field : ObjectField) → "\"${escape field.mapKey}\":" + + let prefixKeyOnFirst = + λ(field : ObjectField) → + NonEmpty/mapHead + Text + (addPrefix "${keystr field} ") + (Block/toLines field.mapValue) + + let prependKeyLine = + λ(field : ObjectField) → + NonEmpty/prepend + Text + (keystr field) + (Block/toLines field.mapValue) + + let renderYAMLField = + λ(field : ObjectField) → + merge + { Simple = + λ(line : Text) → + NonEmpty/singleton Text "${keystr field} ${line}" + , Complex = λ(_ : Lines) → indentTail (prependKeyLine field) + } + field.mapValue + + in merge + { JSON = + renderJSONStruct + "{" + "}" + (NonEmpty/map ObjectField Lines prefixKeyOnFirst fields) + , YAML = + NonEmpty/concat + Text + (NonEmpty/map ObjectField Lines renderYAMLField fields) + } + format + +let renderYAMLArrayField = + λ(block : Block) → + NonEmpty/mapHead + Text + (addPrefix "- ") + (indentTail (Block/toLines block)) + +let renderArray = + λ(format : Format) → + λ(fields : NonEmpty Block) → + merge + { JSON = + renderJSONStruct + "[" + "]" + (NonEmpty/map Block Lines Block/toLines fields) + , YAML = + NonEmpty/concat + Text + (NonEmpty/map Block Lines renderYAMLArrayField fields) + } + format + +let renderAs + : Format → JSON.Type → Text + = λ(format : Format) → + λ(json : JSON.Type) → + blockToText + ( json + Block + { string = λ(x : Text) → Block.Simple "\"${escape x}\"" + , double = λ(x : Double) → Block.Simple (Double/show x) + , integer = λ(x : Integer) → Block.Simple (JSON.renderInteger x) + , object = manyBlocks ObjectField "{}" (renderObject format) + , array = manyBlocks Block "[]" (renderArray format) + , bool = + λ(x : Bool) → Block.Simple (if x then "true" else "false") + , null = Block.Simple "null" + } + ) + +let example0 = + let data = + JSON.array + [ JSON.bool True + , JSON.string "Hello" + , JSON.object + [ { mapKey = "foo", mapValue = JSON.null } + , { mapKey = "bar", mapValue = JSON.double 1.0 } + ] + ] + + let yaml = + assert + : renderAs Format.YAML data + ≡ '' + - true + - "Hello" + - "foo": null + "bar": 1.0 + '' + + let json = + assert + : renderAs Format.JSON data + ≡ '' + [ + true, + "Hello", + { + "foo": null, + "bar": 1.0 + } + ] + '' + + in True + +let example1 = + let data = + JSON.object + [ { mapKey = "zero", mapValue = JSON.array ([] : List JSON.Type) } + , { mapKey = "one", mapValue = JSON.array [ JSON.string "a" ] } + , { mapKey = "two" + , mapValue = JSON.array [ JSON.string "a", JSON.string "b" ] + } + ] + + let yaml = + assert + : renderAs Format.YAML data + ≡ '' + "zero": [] + "one": + - "a" + "two": + - "a" + - "b" + '' + + let json = + assert + : renderAs Format.JSON data + ≡ '' + { + "zero": [], + "one": [ "a" ], + "two": [ + "a", + "b" + ] + } + '' + + in True + +let example2 = + let data = + JSON.object + [ { mapKey = "zero" + , mapValue = + JSON.object + (toMap {=} : List { mapKey : Text, mapValue : JSON.Type }) + } + , { mapKey = "one" + , mapValue = JSON.object (toMap { a = JSON.null }) + } + , { mapKey = "two" + , mapValue = + JSON.object (toMap { a = JSON.null, b = JSON.null }) + } + ] + + let yaml = + assert + : renderAs Format.YAML data + ≡ '' + "zero": {} + "one": + "a": null + "two": + "a": null + "b": null + '' + + let json = + assert + : renderAs Format.JSON data + ≡ '' + { + "zero": {}, + "one": { "a": null }, + "two": { + "a": null, + "b": null + } + } + '' + + in True + +let example3 = + let specialCharacters = + '' + "\${"\b\f"} + ${"\r"} $'' + + let data = + JSON.object + [ { mapKey = specialCharacters + , mapValue = JSON.string specialCharacters + } + ] + + in assert + : renderAs Format.JSON data + ≡ '' + { "\"\\\b\f\n\r\t$": "\"\\\b\f\n\r\t$" } + '' + +in renderAs diff --git a/dhall/Prelude/JSON/renderCompact.dhall b/dhall/Prelude/JSON/renderCompact.dhall new file mode 100644 index 0000000..4447dfd --- /dev/null +++ b/dhall/Prelude/JSON/renderCompact.dhall @@ -0,0 +1,61 @@ +--| This renders JSON on a single line +let JSON = + missing + sha256:5dc1135d5481cfd6fde625aaed9fcbdb7aa7c14f2e76726aa5fdef028a5c10f5 + ? ./core.dhall + +let Text/concatMapSep = + missing + sha256:c272aca80a607bc5963d1fcb38819e7e0d3e72ac4d02b1183b1afb6a91340840 + ? ../Text/concatMapSep + +let renderInteger = + missing + sha256:15b8d2ae46d5002832741927af787761df49798c911e2bf85db7a7b9cb5c078c + ? ./renderInteger.dhall + +let renderCompact + : JSON.Type → Text + = λ(j : JSON.Type) → + j + Text + { string = Text/show + , double = Double/show + , integer = renderInteger + , object = + λ(x : List { mapKey : Text, mapValue : Text }) → + let body = + Text/concatMapSep + "," + { mapKey : Text, mapValue : Text } + ( λ(e : { mapKey : Text, mapValue : Text }) → + " ${Text/show e.mapKey}: ${e.mapValue}" + ) + x + + in "{${body} }" + , array = + λ(x : List Text) → + let body = Text/concatMapSep "," Text (λ(y : Text) → " ${y}") x + + in "[${body} ]" + , bool = λ(x : Bool) → if x then "true" else "false" + , null = "null" + } + +let example = + assert + : renderCompact + ( JSON.array + [ JSON.bool True + , JSON.string "Hello" + , JSON.object + [ { mapKey = "foo", mapValue = JSON.null } + , { mapKey = "bar", mapValue = JSON.double 1.1 } + , { mapKey = "baz", mapValue = JSON.integer +2 } + ] + ] + ) + ≡ "[ true, \"Hello\", { \"foo\": null, \"bar\": 1.1, \"baz\": 2 } ]" + +in renderCompact diff --git a/dhall/Prelude/JSON/renderInteger.dhall b/dhall/Prelude/JSON/renderInteger.dhall new file mode 100644 index 0000000..379f1b6 --- /dev/null +++ b/dhall/Prelude/JSON/renderInteger.dhall @@ -0,0 +1,23 @@ +{-| +Render an `Integer` value as a `JSON number`, according to the JSON standard, in +which a number may not start with a plus sign (`+`). +-} +let Integer/nonNegative = + missing + sha256:b463373f070df6b1c8c7082051e0810fee38b360bab35256187c8c2b6af5c663 + ? ../Integer/nonNegative.dhall + +let renderInteger + : Integer → Text + = λ(integer : Integer) → + if Integer/nonNegative integer + then Natural/show (Integer/clamp integer) + else Integer/show integer + +let positive = assert : renderInteger +1 ≡ "1" + +let zero = assert : renderInteger +0 ≡ "0" + +let negative = assert : renderInteger -1 ≡ "-1" + +in renderInteger diff --git a/dhall/Prelude/JSON/renderYAML b/dhall/Prelude/JSON/renderYAML new file mode 100644 index 0000000..adb23b0 --- /dev/null +++ b/dhall/Prelude/JSON/renderYAML @@ -0,0 +1,3 @@ + missing + sha256:bc71449397bbf48103c3ebbdd570cd27313115e94b2b1b96761d257d5c02d478 +? ./renderYAML.dhall diff --git a/dhall/Prelude/JSON/renderYAML.dhall b/dhall/Prelude/JSON/renderYAML.dhall new file mode 100644 index 0000000..f321b12 --- /dev/null +++ b/dhall/Prelude/JSON/renderYAML.dhall @@ -0,0 +1,49 @@ +{-| +Render a `JSON` value as `Text` in YAML format. + +The generated YAML text will only contain escaped object keys and +string values and might therefore not be very human readable. + +However, it is useful for debugging `JSON` values or for tests. +For anything more sophisticated you should use `dhall-to-json` or +`dhall-to-yaml`. +-} +let JSON = + missing + sha256:5dc1135d5481cfd6fde625aaed9fcbdb7aa7c14f2e76726aa5fdef028a5c10f5 + ? ./core.dhall + +let renderAs = + missing + sha256:c23be039c9601a33d6546fd99a8d72bee8dde5f46176d57cc96613b31a3bb471 + ? ./renderAs.dhall + +let Format = + missing + sha256:d7936b510cfc091faa994652af0eb5feb889cd44bc989edbe4f1eb8c5623caac + ? ./Format.dhall + +let renderYAML + : JSON.Type → Text + = renderAs Format.YAML + +let example0 = + assert + : renderYAML + ( JSON.array + [ JSON.bool True + , JSON.string "Hello" + , JSON.object + [ { mapKey = "foo", mapValue = JSON.null } + , { mapKey = "bar", mapValue = JSON.double 1.0 } + ] + ] + ) + ≡ '' + - true + - "Hello" + - "foo": null + "bar": 1.0 + '' + +in renderYAML diff --git a/dhall/Prelude/JSON/string b/dhall/Prelude/JSON/string new file mode 100644 index 0000000..59e0c71 --- /dev/null +++ b/dhall/Prelude/JSON/string @@ -0,0 +1,3 @@ + missing + sha256:7ddb3a3b9f3ed09ed011d621a10ad9825185cd03503be98a81d42f6afb77940e +? ./string.dhall diff --git a/dhall/Prelude/JSON/string.dhall b/dhall/Prelude/JSON/string.dhall new file mode 100644 index 0000000..7346d66 --- /dev/null +++ b/dhall/Prelude/JSON/string.dhall @@ -0,0 +1,35 @@ +{-| +Create a JSON string from Dhall `Text` + +``` +let JSON = ./package.dhall +in JSON.render (JSON.string "ABC $ \" 🙂") += "\"ABC \\u0024 \\\" 🙂\"" + +let JSON = ./package.dhall +in JSON.render (JSON.string "") += "\"\"" +``` +-} +let JSON = + missing + sha256:40edbc9371979426df63e064333b02689b969c4cfbbccfa481216d2d1a6e9759 + ? ./Type.dhall + +let string + : Text → JSON + = λ(x : Text) → + λ(JSON : Type) → + λ ( json + : { array : List JSON → JSON + , bool : Bool → JSON + , double : Double → JSON + , integer : Integer → JSON + , null : JSON + , object : List { mapKey : Text, mapValue : JSON } → JSON + , string : Text → JSON + } + ) → + json.string x + +in string diff --git a/dhall/Prelude/JSON/tagInline b/dhall/Prelude/JSON/tagInline new file mode 100644 index 0000000..2897387 --- /dev/null +++ b/dhall/Prelude/JSON/tagInline @@ -0,0 +1,3 @@ + missing + sha256:49559ac11906ba6cc9eac25753e31e7addb13bc760df108024174c55523984c4 +? ./tagInline.dhall diff --git a/dhall/Prelude/JSON/tagInline.dhall b/dhall/Prelude/JSON/tagInline.dhall new file mode 100644 index 0000000..b44d4da --- /dev/null +++ b/dhall/Prelude/JSON/tagInline.dhall @@ -0,0 +1,29 @@ +--| Prepare a union value for JSON- or YAML-encoding with the inline layout +let Nesting = + missing + sha256:6284802edd41d5d725aa1ec7687e614e21ad1be7e14dd10996bfa9625105c335 + ? ./Nesting.dhall + +let Tagged = + missing + sha256:21feca7d2b23f210d0696131d792e18a7d24fdcc85d41a49ba85b98670eba194 + ? ./Tagged.dhall + +let tagInline + : Text → ∀(a : Type) → a → Tagged a + = λ(tagFieldName : Text) → + λ(a : Type) → + λ(contents : a) → + { nesting = Nesting.Inline, field = tagFieldName, contents } + +let example0 = + let Example = < Left : { foo : Natural } | Right : { bar : Bool } > + + in assert + : tagInline "name" Example (Example.Left { foo = 2 }) + ≡ { field = "name" + , nesting = Nesting.Inline + , contents = Example.Left { foo = 2 } + } + +in tagInline diff --git a/dhall/Prelude/JSON/tagNested b/dhall/Prelude/JSON/tagNested new file mode 100644 index 0000000..1a00be1 --- /dev/null +++ b/dhall/Prelude/JSON/tagNested @@ -0,0 +1,3 @@ + missing + sha256:93a7415853b7677c832246efadc8e880c1b641a23589286a836a384ca311d26f +? ./tagNested.dhall diff --git a/dhall/Prelude/JSON/tagNested.dhall b/dhall/Prelude/JSON/tagNested.dhall new file mode 100644 index 0000000..a9cac70 --- /dev/null +++ b/dhall/Prelude/JSON/tagNested.dhall @@ -0,0 +1,33 @@ +--| Prepare a union value for JSON- or YAML-encoding with the nested layout +let Nesting = + missing + sha256:6284802edd41d5d725aa1ec7687e614e21ad1be7e14dd10996bfa9625105c335 + ? ./Nesting.dhall + +let Tagged = + missing + sha256:21feca7d2b23f210d0696131d792e18a7d24fdcc85d41a49ba85b98670eba194 + ? ./Tagged.dhall + +let tagNested + : Text → Text → ∀(a : Type) → a → Tagged a + = λ(contentsFieldName : Text) → + λ(tagFieldName : Text) → + λ(a : Type) → + λ(contents : a) → + { nesting = Nesting.Nested contentsFieldName + , field = tagFieldName + , contents + } + +let example0 = + let Example = < Left : { foo : Natural } | Right : { bar : Bool } > + + in assert + : tagNested "value" "name" Example (Example.Left { foo = 2 }) + ≡ { field = "name" + , nesting = Nesting.Nested "value" + , contents = Example.Left { foo = 2 } + } + +in tagNested diff --git a/dhall/Prelude/List/all b/dhall/Prelude/List/all new file mode 100644 index 0000000..98c345f --- /dev/null +++ b/dhall/Prelude/List/all @@ -0,0 +1,3 @@ + missing + sha256:7ac5bb6f77e9ffe9e2356d90968d39764a9a32f75980206e6b12f815bb83dd15 +? ./all.dhall diff --git a/dhall/Prelude/List/all.dhall b/dhall/Prelude/List/all.dhall new file mode 100644 index 0000000..11b1613 --- /dev/null +++ b/dhall/Prelude/List/all.dhall @@ -0,0 +1,16 @@ +{-| +Returns `True` if the supplied function returns `True` for all elements in the +`List` +-} +let all + : ∀(a : Type) → (a → Bool) → List a → Bool + = λ(a : Type) → + λ(f : a → Bool) → + λ(xs : List a) → + List/fold a xs Bool (λ(x : a) → λ(r : Bool) → f x && r) True + +let example0 = assert : all Natural Natural/even [ 2, 3, 5 ] ≡ False + +let example1 = assert : all Natural Natural/even ([] : List Natural) ≡ True + +in all diff --git a/dhall/Prelude/List/any b/dhall/Prelude/List/any new file mode 100644 index 0000000..fe17799 --- /dev/null +++ b/dhall/Prelude/List/any @@ -0,0 +1,3 @@ + missing + sha256:b8e9e13b25e799f342a81f6eda4075906eb1a19dfdcb10a0ca25925eba4033b8 +? ./any.dhall diff --git a/dhall/Prelude/List/any.dhall b/dhall/Prelude/List/any.dhall new file mode 100644 index 0000000..130bf0b --- /dev/null +++ b/dhall/Prelude/List/any.dhall @@ -0,0 +1,16 @@ +{-| +Returns `True` if the supplied function returns `True` for any element in the +`List` +-} +let any + : ∀(a : Type) → (a → Bool) → List a → Bool + = λ(a : Type) → + λ(f : a → Bool) → + λ(xs : List a) → + List/fold a xs Bool (λ(x : a) → λ(r : Bool) → f x || r) False + +let example0 = assert : any Natural Natural/even [ 2, 3, 5 ] ≡ True + +let example1 = assert : any Natural Natural/even ([] : List Natural) ≡ False + +in any diff --git a/dhall/Prelude/List/build b/dhall/Prelude/List/build new file mode 100644 index 0000000..7088493 --- /dev/null +++ b/dhall/Prelude/List/build @@ -0,0 +1,3 @@ + missing + sha256:8cf73fc1e115cfcb79bb9cd490bfcbd45c824e93c57a0e64c86c0c72e9ebbe42 +? ./build.dhall diff --git a/dhall/Prelude/List/build.dhall b/dhall/Prelude/List/build.dhall new file mode 100644 index 0000000..c59c3c5 --- /dev/null +++ b/dhall/Prelude/List/build.dhall @@ -0,0 +1,30 @@ +--| `build` is the inverse of `fold` +let build + : ∀(a : Type) → + (∀(list : Type) → ∀(cons : a → list → list) → ∀(nil : list) → list) → + List a + = List/build + +let example0 = + assert + : build + Text + ( λ(list : Type) → + λ(cons : Text → list → list) → + λ(nil : list) → + cons "ABC" (cons "DEF" nil) + ) + ≡ [ "ABC", "DEF" ] + +let example1 = + assert + : build + Text + ( λ(list : Type) → + λ(cons : Text → list → list) → + λ(nil : list) → + nil + ) + ≡ ([] : List Text) + +in build diff --git a/dhall/Prelude/List/concat b/dhall/Prelude/List/concat new file mode 100644 index 0000000..cf04428 --- /dev/null +++ b/dhall/Prelude/List/concat @@ -0,0 +1,3 @@ + missing + sha256:54e43278be13276e03bd1afa89e562e94a0a006377ebea7db14c7562b0de292b +? ./concat.dhall diff --git a/dhall/Prelude/List/concat.dhall b/dhall/Prelude/List/concat.dhall new file mode 100644 index 0000000..ee17d84 --- /dev/null +++ b/dhall/Prelude/List/concat.dhall @@ -0,0 +1,34 @@ +--| Concatenate a `List` of `List`s into a single `List` +let concat + : ∀(a : Type) → List (List a) → List a + = λ(a : Type) → + λ(xss : List (List a)) → + List/build + a + ( λ(list : Type) → + λ(cons : a → list → list) → + λ(nil : list) → + List/fold + (List a) + xss + list + (λ(xs : List a) → λ(ys : list) → List/fold a xs list cons ys) + nil + ) + +let example0 = + assert + : concat Natural [ [ 0, 1, 2 ], [ 3, 4 ], [ 5, 6, 7, 8 ] ] + ≡ [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ] + +let example1 = + assert + : concat + Natural + [ [] : List Natural, [] : List Natural, [] : List Natural ] + ≡ ([] : List Natural) + +let example2 = + assert : concat Natural ([] : List (List Natural)) ≡ ([] : List Natural) + +in concat diff --git a/dhall/Prelude/List/concatMap b/dhall/Prelude/List/concatMap new file mode 100644 index 0000000..c53aca5 --- /dev/null +++ b/dhall/Prelude/List/concatMap @@ -0,0 +1,3 @@ + missing + sha256:3b2167061d11fda1e4f6de0522cbe83e0d5ac4ef5ddf6bb0b2064470c5d3fb64 +? ./concatMap.dhall diff --git a/dhall/Prelude/List/concatMap.dhall b/dhall/Prelude/List/concatMap.dhall new file mode 100644 index 0000000..4cc2e77 --- /dev/null +++ b/dhall/Prelude/List/concatMap.dhall @@ -0,0 +1,32 @@ +{-| +Transform a list by applying a function to each element and flattening the +results +-} +let concatMap + : ∀(a : Type) → ∀(b : Type) → (a → List b) → List a → List b + = λ(a : Type) → + λ(b : Type) → + λ(f : a → List b) → + λ(xs : List a) → + List/build + b + ( λ(list : Type) → + λ(cons : b → list → list) → + List/fold a xs list (λ(x : a) → List/fold b (f x) list cons) + ) + +let example0 = + assert + : concatMap Natural Natural (λ(n : Natural) → [ n, n ]) [ 2, 3, 5 ] + ≡ [ 2, 2, 3, 3, 5, 5 ] + +let example1 = + assert + : concatMap + Natural + Natural + (λ(n : Natural) → [ n, n ]) + ([] : List Natural) + ≡ ([] : List Natural) + +in concatMap diff --git a/dhall/Prelude/List/default b/dhall/Prelude/List/default new file mode 100644 index 0000000..0b66b72 --- /dev/null +++ b/dhall/Prelude/List/default @@ -0,0 +1,3 @@ + missing + sha256:fd77809e497227403f42848ffcda05a3efab442d961027c34f3e31d5d24e6379 +? ./default.dhall diff --git a/dhall/Prelude/List/default.dhall b/dhall/Prelude/List/default.dhall new file mode 100644 index 0000000..15b0bb2 --- /dev/null +++ b/dhall/Prelude/List/default.dhall @@ -0,0 +1,15 @@ +{-| +Unpack an `Optional` containing a `List`, defaulting to an empty list when the +`Optional` is `None` +-} +let default + : ∀(a : Type) → Optional (List a) → List a + = λ(a : Type) → + λ(o : Optional (List a)) → + merge { Some = λ(l : List a) → l, None = [] : List a } o + +let example0 = assert : default Bool (None (List Bool)) ≡ ([] : List Bool) + +let example1 = assert : default Bool (Some [ True ]) ≡ [ True ] + +in default diff --git a/dhall/Prelude/List/drop b/dhall/Prelude/List/drop new file mode 100644 index 0000000..c3bbeb1 --- /dev/null +++ b/dhall/Prelude/List/drop @@ -0,0 +1,3 @@ + missing + sha256:af983ba3ead494dd72beed05c0f3a17c36a4244adedf7ced502c6512196ed0cf +? ./drop.dhall diff --git a/dhall/Prelude/List/drop.dhall b/dhall/Prelude/List/drop.dhall new file mode 100644 index 0000000..e4e0cd9 --- /dev/null +++ b/dhall/Prelude/List/drop.dhall @@ -0,0 +1,28 @@ +--| Remove first `n` elements of a list +let Natural/greaterThanEqual = + missing + sha256:30ebfab0febd7aa0ccccfdf3dc36ee6d50f0117f35dd4a9b034750b7e885a1a4 + ? ../Natural/greaterThanEqual.dhall + +let drop + : ∀(n : Natural) → ∀(a : Type) → List a → List a + = λ(n : Natural) → + λ(a : Type) → + λ(xs : List a) → + List/fold + { index : Natural, value : a } + (List/indexed a xs) + (List a) + ( λ(x : { index : Natural, value : a }) → + λ(xs : List a) → + if Natural/greaterThanEqual x.index n + then [ x.value ] # xs + else xs + ) + ([] : List a) + +let example = assert : drop 2 Natural [ 2, 3, 5 ] ≡ [ 5 ] + +let example = assert : drop 5 Natural [ 2, 3, 5 ] ≡ ([] : List Natural) + +in drop diff --git a/dhall/Prelude/List/empty b/dhall/Prelude/List/empty new file mode 100644 index 0000000..ec54ff2 --- /dev/null +++ b/dhall/Prelude/List/empty @@ -0,0 +1,3 @@ + missing + sha256:b2f561f35098c457353723c93a22bd5de28d26ecc5370814bef9dfda421e0147 +? ./empty.dhall diff --git a/dhall/Prelude/List/empty.dhall b/dhall/Prelude/List/empty.dhall new file mode 100644 index 0000000..fe66a71 --- /dev/null +++ b/dhall/Prelude/List/empty.dhall @@ -0,0 +1,8 @@ +--| An empty list of the given type +let empty + : ∀(a : Type) → List a + = λ(a : Type) → [] : List a + +let example0 = assert : empty Bool ≡ ([] : List Bool) + +in empty diff --git a/dhall/Prelude/List/filter b/dhall/Prelude/List/filter new file mode 100644 index 0000000..f1f569a --- /dev/null +++ b/dhall/Prelude/List/filter @@ -0,0 +1,3 @@ + missing + sha256:8ebfede5bbfe09675f246c33eb83964880ac615c4b1be8d856076fdbc4b26ba6 +? ./filter.dhall diff --git a/dhall/Prelude/List/filter.dhall b/dhall/Prelude/List/filter.dhall new file mode 100644 index 0000000..6b2a63f --- /dev/null +++ b/dhall/Prelude/List/filter.dhall @@ -0,0 +1,22 @@ +--| Only keep elements of the list where the supplied function returns `True` +let filter + : ∀(a : Type) → (a → Bool) → List a → List a + = λ(a : Type) → + λ(f : a → Bool) → + λ(xs : List a) → + List/build + a + ( λ(list : Type) → + λ(cons : a → list → list) → + List/fold + a + xs + list + (λ(x : a) → λ(xs : list) → if f x then cons x xs else xs) + ) + +let example0 = assert : filter Natural Natural/even [ 2, 3, 5 ] ≡ [ 2 ] + +let example1 = assert : filter Natural Natural/odd [ 2, 3, 5 ] ≡ [ 3, 5 ] + +in filter diff --git a/dhall/Prelude/List/filterMap.dhall b/dhall/Prelude/List/filterMap.dhall new file mode 100644 index 0000000..45d5810 --- /dev/null +++ b/dhall/Prelude/List/filterMap.dhall @@ -0,0 +1,45 @@ +--| Transform a list by applying a function to each element and omitting None results. +let List/concatMap = + missing + sha256:3b2167061d11fda1e4f6de0522cbe83e0d5ac4ef5ddf6bb0b2064470c5d3fb64 + ? ./concatMap.dhall + +let Optional/toList = + missing + sha256:d78f160c619119ef12389e48a629ce293d69f7624c8d016b7a4767ab400344c4 + ? ../Optional/toList.dhall + +let filterMap + : ∀(a : Type) → ∀(b : Type) → (a → Optional b) → List a → List b + = λ(a : Type) → + λ(b : Type) → + λ(f : a → Optional b) → + List/concatMap a b (λ(x : a) → Optional/toList b (f x)) + +let example0 = + assert + : filterMap + (List Natural) + Natural + (List/head Natural) + [ [ 1 ], [] : List Natural, [ 3, 4 ] ] + ≡ [ 1, 3 ] + +let example1 = + let Example = < Left : Bool | Right : Natural > + + in assert + : filterMap + Example + Natural + ( λ(x : Example) → + merge + { Left = λ(_ : Bool) → None Natural + , Right = λ(n : Natural) → Some n + } + x + ) + [ Example.Left False, Example.Right 2, Example.Left True ] + ≡ [ 2 ] + +in filterMap diff --git a/dhall/Prelude/List/fold b/dhall/Prelude/List/fold new file mode 100644 index 0000000..297431f --- /dev/null +++ b/dhall/Prelude/List/fold @@ -0,0 +1,3 @@ + missing + sha256:10bb945c25ab3943bd9df5a32e633cbfae112b7d3af38591784687e436a8d814 +? ./fold.dhall diff --git a/dhall/Prelude/List/fold.dhall b/dhall/Prelude/List/fold.dhall new file mode 100644 index 0000000..ee8b8e9 --- /dev/null +++ b/dhall/Prelude/List/fold.dhall @@ -0,0 +1,43 @@ +{-| +`fold` is the primitive function for consuming `List`s + +If you treat the list `[ x, y, z ]` as `cons x (cons y (cons z nil))`, then a +`fold` just replaces each `cons` and `nil` with something else +-} +let fold + : ∀(a : Type) → + List a → + ∀(list : Type) → + ∀(cons : a → list → list) → + ∀(nil : list) → + list + = List/fold + +let example0 = + assert + : fold + Natural + [ 2, 3, 5 ] + Text + (λ(x : Natural) → λ(y : Text) → Natural/show x ++ y) + "0" + ≡ "2350" + +let example1 = + λ(nil : Text) → + assert + : fold + Natural + [ 2, 3, 5 ] + Text + (λ(x : Natural) → λ(y : Text) → Natural/show x ++ y) + nil + ≡ "2" ++ ("3" ++ ("5" ++ nil)) + +let example2 = + λ(cons : Natural → Text → Text) → + λ(nil : Text) → + assert + : fold Natural [ 2, 3, 5 ] Text cons nil ≡ cons 2 (cons 3 (cons 5 nil)) + +in fold diff --git a/dhall/Prelude/List/foldLeft.dhall b/dhall/Prelude/List/foldLeft.dhall new file mode 100644 index 0000000..c943877 --- /dev/null +++ b/dhall/Prelude/List/foldLeft.dhall @@ -0,0 +1,60 @@ +{-| +`foldLeft` is like `List/fold` except that the accumulation starts from the left + +If you treat the list `[ x, y, z ]` as `cons (cons (cons nil x) y) z`, then +`foldLeft` just replaces each `cons` and `nil` with something else +-} +let foldLeft + : ∀(a : Type) → + List a → + ∀(list : Type) → + ∀(cons : list → a → list) → + ∀(nil : list) → + list + = λ(a : Type) → + λ(xs : List a) → + λ(list : Type) → + λ(cons : list → a → list) → + λ(nil : list) → + List/fold + a + xs + (list → list) + (λ(x : a) → λ(f : list → list) → λ(l : list) → f (cons l x)) + (λ(l : list) → l) + nil + +let example0 = + assert + : foldLeft + Natural + [ 2, 3, 5 ] + Text + (λ(x : Text) → λ(y : Natural) → x ++ Natural/show y) + "0" + ≡ "0235" + +let example1 = + assert + : ( λ(nil : Text) → + foldLeft + Natural + [ 2, 3, 5 ] + Text + (λ(x : Text) → λ(y : Natural) → x ++ Natural/show y) + nil + ) + ≡ (λ(nil : Text) → nil ++ "2" ++ "3" ++ "5") + +let example2 = + assert + : ( λ(cons : Text → Natural → Text) → + λ(nil : Text) → + foldLeft Natural [ 2, 3, 5 ] Text cons nil + ) + ≡ ( λ(cons : Text → Natural → Text) → + λ(nil : Text) → + cons (cons (cons nil 2) 3) 5 + ) + +in foldLeft diff --git a/dhall/Prelude/List/generate b/dhall/Prelude/List/generate new file mode 100644 index 0000000..b137d73 --- /dev/null +++ b/dhall/Prelude/List/generate @@ -0,0 +1,3 @@ + missing + sha256:78ff1ad96c08b88a8263eea7bc8381c078225cfcb759c496f792edb5a5e0b1a4 +? ./generate.dhall diff --git a/dhall/Prelude/List/generate.dhall b/dhall/Prelude/List/generate.dhall new file mode 100644 index 0000000..2afdeb7 --- /dev/null +++ b/dhall/Prelude/List/generate.dhall @@ -0,0 +1,35 @@ +{-| +Build a list by calling the supplied function on all `Natural` numbers from `0` +up to but not including the supplied `Natural` number +-} +let generate + : Natural → ∀(a : Type) → (Natural → a) → List a + = λ(n : Natural) → + λ(a : Type) → + λ(f : Natural → a) → + List/build + a + ( λ(list : Type) → + λ(cons : a → list → list) → + List/fold + { index : Natural, value : {} } + ( List/indexed + {} + ( List/build + {} + ( λ(list : Type) → + λ(cons : {} → list → list) → + Natural/fold n list (cons {=}) + ) + ) + ) + list + (λ(x : { index : Natural, value : {} }) → cons (f x.index)) + ) + +let example0 = + assert : generate 5 Bool Natural/even ≡ [ True, False, True, False, True ] + +let example1 = assert : generate 0 Bool Natural/even ≡ ([] : List Bool) + +in generate diff --git a/dhall/Prelude/List/head b/dhall/Prelude/List/head new file mode 100644 index 0000000..72a3188 --- /dev/null +++ b/dhall/Prelude/List/head @@ -0,0 +1,3 @@ + missing + sha256:0d2e65ba0aea908377e46d22020dc3ad970284f4ee4eb8e6b8c51e53038c0026 +? ./head.dhall diff --git a/dhall/Prelude/List/head.dhall b/dhall/Prelude/List/head.dhall new file mode 100644 index 0000000..a50f692 --- /dev/null +++ b/dhall/Prelude/List/head.dhall @@ -0,0 +1,10 @@ +--| Retrieve the first element of the list +let head + : ∀(a : Type) → List a → Optional a + = List/head + +let example0 = assert : head Natural [ 0, 1, 2 ] ≡ Some 0 + +let example1 = assert : head Natural ([] : List Natural) ≡ None Natural + +in head diff --git a/dhall/Prelude/List/index b/dhall/Prelude/List/index new file mode 100644 index 0000000..4c03d35 --- /dev/null +++ b/dhall/Prelude/List/index @@ -0,0 +1,3 @@ + missing + sha256:e657b55ecae4d899465c3032cb1a64c6aa6dc2aa3034204f3c15ce5c96c03e63 +? ./index.dhall diff --git a/dhall/Prelude/List/index.dhall b/dhall/Prelude/List/index.dhall new file mode 100644 index 0000000..1aa9d35 --- /dev/null +++ b/dhall/Prelude/List/index.dhall @@ -0,0 +1,18 @@ +--| Retrieve an element from a `List` using its 0-based index +let drop = + missing + sha256:af983ba3ead494dd72beed05c0f3a17c36a4244adedf7ced502c6512196ed0cf + ? ./drop.dhall + +let index + : Natural → ∀(a : Type) → List a → Optional a + = λ(n : Natural) → λ(a : Type) → λ(xs : List a) → List/head a (drop n a xs) + +let property = + λ(n : Natural) → λ(a : Type) → assert : index n a ([] : List a) ≡ None a + +let example0 = assert : index 1 Natural [ 2, 3, 5 ] ≡ Some 3 + +let example1 = assert : index 1 Natural ([] : List Natural) ≡ None Natural + +in index diff --git a/dhall/Prelude/List/indexed b/dhall/Prelude/List/indexed new file mode 100644 index 0000000..267febb --- /dev/null +++ b/dhall/Prelude/List/indexed @@ -0,0 +1,3 @@ + missing + sha256:58bb44457fa81adf26f5123c1b2e8bef0c5aa22dac5fa5ebdfb7da84563b027f +? ./indexed.dhall diff --git a/dhall/Prelude/List/indexed.dhall b/dhall/Prelude/List/indexed.dhall new file mode 100644 index 0000000..20500e1 --- /dev/null +++ b/dhall/Prelude/List/indexed.dhall @@ -0,0 +1,19 @@ +--| Tag each element of the list with its index +let indexed + : ∀(a : Type) → List a → List { index : Natural, value : a } + = List/indexed + +let example0 = + assert + : indexed Bool [ True, False, True ] + ≡ [ { index = 0, value = True } + , { index = 1, value = False } + , { index = 2, value = True } + ] + +let example1 = + assert + : indexed Bool ([] : List Bool) + ≡ ([] : List { index : Natural, value : Bool }) + +in indexed diff --git a/dhall/Prelude/List/iterate b/dhall/Prelude/List/iterate new file mode 100644 index 0000000..a097e02 --- /dev/null +++ b/dhall/Prelude/List/iterate @@ -0,0 +1,3 @@ + missing + sha256:e4999ccce190a2e2a6ab9cb188e3af6c40df474087827153005293f11bfe1d26 +? ./iterate.dhall diff --git a/dhall/Prelude/List/iterate.dhall b/dhall/Prelude/List/iterate.dhall new file mode 100644 index 0000000..02fed82 --- /dev/null +++ b/dhall/Prelude/List/iterate.dhall @@ -0,0 +1,42 @@ +{-| +Generate a list of the specified length given a seed value and transition +function +-} +let iterate + : Natural → ∀(a : Type) → (a → a) → a → List a + = λ(n : Natural) → + λ(a : Type) → + λ(f : a → a) → + λ(x : a) → + List/build + a + ( λ(list : Type) → + λ(cons : a → list → list) → + List/fold + { index : Natural, value : {} } + ( List/indexed + {} + ( List/build + {} + ( λ(list : Type) → + λ(cons : {} → list → list) → + Natural/fold n list (cons {=}) + ) + ) + ) + list + ( λ(y : { index : Natural, value : {} }) → + cons (Natural/fold y.index a f x) + ) + ) + +let example0 = + assert + : iterate 10 Natural (λ(x : Natural) → x * 2) 1 + ≡ [ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 ] + +let example1 = + assert + : iterate 0 Natural (λ(x : Natural) → x * 2) 1 ≡ ([] : List Natural) + +in iterate diff --git a/dhall/Prelude/List/last b/dhall/Prelude/List/last new file mode 100644 index 0000000..d276ca4 --- /dev/null +++ b/dhall/Prelude/List/last @@ -0,0 +1,3 @@ + missing + sha256:741226b741af152a1638491cdff7f3aa74baf080ada2e63429483f3d195a984d +? ./last.dhall diff --git a/dhall/Prelude/List/last.dhall b/dhall/Prelude/List/last.dhall new file mode 100644 index 0000000..2e695fb --- /dev/null +++ b/dhall/Prelude/List/last.dhall @@ -0,0 +1,10 @@ +--| Retrieve the last element of the list +let last + : ∀(a : Type) → List a → Optional a + = List/last + +let example0 = assert : last Natural [ 0, 1, 2 ] ≡ Some 2 + +let example1 = assert : last Natural ([] : List Natural) ≡ None Natural + +in last diff --git a/dhall/Prelude/List/length b/dhall/Prelude/List/length new file mode 100644 index 0000000..b330011 --- /dev/null +++ b/dhall/Prelude/List/length @@ -0,0 +1,3 @@ + missing + sha256:42c6812c7a9e3c6e6fad88f77c5b3849503964e071cb784e22c38c888a401461 +? ./length.dhall diff --git a/dhall/Prelude/List/length.dhall b/dhall/Prelude/List/length.dhall new file mode 100644 index 0000000..1238fd5 --- /dev/null +++ b/dhall/Prelude/List/length.dhall @@ -0,0 +1,10 @@ +--| Returns the number of elements in a list +let length + : ∀(a : Type) → List a → Natural + = List/length + +let example0 = assert : length Natural [ 0, 1, 2 ] ≡ 3 + +let example1 = assert : length Natural ([] : List Natural) ≡ 0 + +in length diff --git a/dhall/Prelude/List/map b/dhall/Prelude/List/map new file mode 100644 index 0000000..9e5229a --- /dev/null +++ b/dhall/Prelude/List/map @@ -0,0 +1,3 @@ + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 +? ./map.dhall diff --git a/dhall/Prelude/List/map.dhall b/dhall/Prelude/List/map.dhall new file mode 100644 index 0000000..70fc570 --- /dev/null +++ b/dhall/Prelude/List/map.dhall @@ -0,0 +1,23 @@ +--| Transform a list by applying a function to each element +let map + : ∀(a : Type) → ∀(b : Type) → (a → b) → List a → List b + = λ(a : Type) → + λ(b : Type) → + λ(f : a → b) → + λ(xs : List a) → + List/build + b + ( λ(list : Type) → + λ(cons : b → list → list) → + List/fold a xs list (λ(x : a) → cons (f x)) + ) + +let example0 = + assert + : map Natural Bool Natural/even [ 2, 3, 5 ] ≡ [ True, False, False ] + +let example1 = + assert + : map Natural Bool Natural/even ([] : List Natural) ≡ ([] : List Bool) + +in map diff --git a/dhall/Prelude/List/mapMaybe.dhall b/dhall/Prelude/List/mapMaybe.dhall new file mode 100644 index 0000000..686076e --- /dev/null +++ b/dhall/Prelude/List/mapMaybe.dhall @@ -0,0 +1,37 @@ +--| Apply a function across a list, keeping only the `Some` results. +let List/unpackOptionals = + missing + sha256:0cbaa920f429cf7fc3907f8a9143203fe948883913560e6e1043223e6b3d05e4 + ? ./unpackOptionals.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ./map.dhall + +let mapMaybe + : ∀(a : Type) → ∀(b : Type) → (a → Optional b) → List a → List b + = λ(a : Type) → + λ(b : Type) → + λ(f : a → Optional b) → + λ(xs : List a) → + List/unpackOptionals b (List/map a (Optional b) f xs) + +let property = + λ(a : Type) → + λ(b : Type) → + λ(f : a → Optional b) → + assert : mapMaybe a b f ([] : List a) ≡ ([] : List b) + +let example0 = + assert + : mapMaybe + Natural + Text + ( λ(n : Natural) → + if Natural/isZero n then None Text else Some (Natural/show n) + ) + [ 0, 1, 2, 3 ] + ≡ [ "1", "2", "3" ] + +in mapMaybe diff --git a/dhall/Prelude/List/mapWithIndex b/dhall/Prelude/List/mapWithIndex new file mode 100644 index 0000000..3000350 --- /dev/null +++ b/dhall/Prelude/List/mapWithIndex @@ -0,0 +1,3 @@ + missing + sha256:98599e0b55c5d3ae75264ba90657c6f68c7ce32834bd12b215acaea711eed6eb +? ./mapWithIndex.dhall diff --git a/dhall/Prelude/List/mapWithIndex.dhall b/dhall/Prelude/List/mapWithIndex.dhall new file mode 100644 index 0000000..63a2a33 --- /dev/null +++ b/dhall/Prelude/List/mapWithIndex.dhall @@ -0,0 +1,41 @@ +--| Transform a list by applying a function to each element with its index +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ./map.dhall + +let List/mapWithIndex + : ∀(a : Type) → ∀(b : Type) → (Natural → a → b) → List a → List b + = λ(a : Type) → + λ(b : Type) → + λ(f : Natural → a → b) → + λ(xs : List a) → + List/map + { index : Natural, value : a } + b + (λ(i : { index : Natural, value : a }) → f i.index i.value) + (List/indexed a xs) + +let List/empty = + missing + sha256:b2f561f35098c457353723c93a22bd5de28d26ecc5370814bef9dfda421e0147 + ? ./empty.dhall + +let List/replicate = + missing + sha256:d4250b45278f2d692302489ac3e78280acb238d27541c837ce46911ff3baa347 + ? ./replicate.dhall + +let example0 = + assert + : List/mapWithIndex + Text + (List Text) + ( λ(index : Natural) → + λ(value : Text) → + List/replicate index Text value + ) + [ "A", "B", "C" ] + ≡ [ List/empty Text, [ "B" ], [ "C", "C" ] ] + +in List/mapWithIndex diff --git a/dhall/Prelude/List/null b/dhall/Prelude/List/null new file mode 100644 index 0000000..1f88489 --- /dev/null +++ b/dhall/Prelude/List/null @@ -0,0 +1,3 @@ + missing + sha256:2338e39637e9a50d66ae1482c0ed559bbcc11e9442bfca8f8c176bbcd9c4fc80 +? ./null.dhall diff --git a/dhall/Prelude/List/null.dhall b/dhall/Prelude/List/null.dhall new file mode 100644 index 0000000..fd11976 --- /dev/null +++ b/dhall/Prelude/List/null.dhall @@ -0,0 +1,10 @@ +--| Returns `True` if the `List` is empty and `False` otherwise +let null + : ∀(a : Type) → List a → Bool + = λ(a : Type) → λ(xs : List a) → Natural/isZero (List/length a xs) + +let example0 = assert : null Natural [ 0, 1, 2 ] ≡ False + +let example1 = assert : null Natural ([] : List Natural) ≡ True + +in null diff --git a/dhall/Prelude/List/package.dhall b/dhall/Prelude/List/package.dhall new file mode 100644 index 0000000..b63fb18 --- /dev/null +++ b/dhall/Prelude/List/package.dhall @@ -0,0 +1,125 @@ +{ all = + missing + sha256:7ac5bb6f77e9ffe9e2356d90968d39764a9a32f75980206e6b12f815bb83dd15 + ? ./all.dhall +, any = + missing + sha256:b8e9e13b25e799f342a81f6eda4075906eb1a19dfdcb10a0ca25925eba4033b8 + ? ./any.dhall +, build = + missing + sha256:8cf73fc1e115cfcb79bb9cd490bfcbd45c824e93c57a0e64c86c0c72e9ebbe42 + ? ./build.dhall +, concat = + missing + sha256:54e43278be13276e03bd1afa89e562e94a0a006377ebea7db14c7562b0de292b + ? ./concat.dhall +, concatMap = + missing + sha256:3b2167061d11fda1e4f6de0522cbe83e0d5ac4ef5ddf6bb0b2064470c5d3fb64 + ? ./concatMap.dhall +, default = + missing + sha256:fd77809e497227403f42848ffcda05a3efab442d961027c34f3e31d5d24e6379 + ? ./default.dhall +, drop = + missing + sha256:af983ba3ead494dd72beed05c0f3a17c36a4244adedf7ced502c6512196ed0cf + ? ./drop.dhall +, empty = + missing + sha256:b2f561f35098c457353723c93a22bd5de28d26ecc5370814bef9dfda421e0147 + ? ./empty.dhall +, filter = + missing + sha256:8ebfede5bbfe09675f246c33eb83964880ac615c4b1be8d856076fdbc4b26ba6 + ? ./filter.dhall +, filterMap = + missing + sha256:94b7ed4204d1c79aaf55527ef51024e7085b8dd2896952cffbd12d8f95e16f46 + ? ./filterMap.dhall +, fold = + missing + sha256:10bb945c25ab3943bd9df5a32e633cbfae112b7d3af38591784687e436a8d814 + ? ./fold.dhall +, foldLeft = + missing + sha256:3c6ab57950fe644906b7bbdef0b9523440b6ee17773ebb8cbd41ffacb8bfab61 + ? ./foldLeft.dhall +, generate = + missing + sha256:78ff1ad96c08b88a8263eea7bc8381c078225cfcb759c496f792edb5a5e0b1a4 + ? ./generate.dhall +, head = + missing + sha256:0d2e65ba0aea908377e46d22020dc3ad970284f4ee4eb8e6b8c51e53038c0026 + ? ./head.dhall +, index = + missing + sha256:e657b55ecae4d899465c3032cb1a64c6aa6dc2aa3034204f3c15ce5c96c03e63 + ? ./index.dhall +, indexed = + missing + sha256:58bb44457fa81adf26f5123c1b2e8bef0c5aa22dac5fa5ebdfb7da84563b027f + ? ./indexed.dhall +, iterate = + missing + sha256:e4999ccce190a2e2a6ab9cb188e3af6c40df474087827153005293f11bfe1d26 + ? ./iterate.dhall +, last = + missing + sha256:741226b741af152a1638491cdff7f3aa74baf080ada2e63429483f3d195a984d + ? ./last.dhall +, length = + missing + sha256:42c6812c7a9e3c6e6fad88f77c5b3849503964e071cb784e22c38c888a401461 + ? ./length.dhall +, map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ./map.dhall +, mapMaybe = + missing + sha256:6f3c4f8c94577b46e7d30f8df7e82a269b0ad0a7e18c0f0370f243fd1127e77f + ? ./mapMaybe.dhall +, mapWithIndex = + missing + sha256:98599e0b55c5d3ae75264ba90657c6f68c7ce32834bd12b215acaea711eed6eb + ? ./mapWithIndex.dhall +, null = + missing + sha256:2338e39637e9a50d66ae1482c0ed559bbcc11e9442bfca8f8c176bbcd9c4fc80 + ? ./null.dhall +, partition = + missing + sha256:38147ac6d750a6492736dd90cc967bf09aa405c499de943c64fab7b86ae02f03 + ? ./partition.dhall +, replicate = + missing + sha256:d4250b45278f2d692302489ac3e78280acb238d27541c837ce46911ff3baa347 + ? ./replicate.dhall +, reverse = + missing + sha256:ad99d224d61852de6696da5a7d04c98dbe676fe67d5e4ef4f19e9aaa27006e9d + ? ./reverse.dhall +, shifted = + missing + sha256:54fb22c7e952ebce1cfc0fcdd33ce4cfa817bff9d6564af268dea6685f8b5dfe + ? ./shifted.dhall +, take = + missing + sha256:b3e08ee8c3a5bf3d8ccee6b2b2008fbb8e51e7373aef6f1af67ad10078c9fbfa + ? ./take.dhall +, unpackOptionals = + missing + sha256:0cbaa920f429cf7fc3907f8a9143203fe948883913560e6e1043223e6b3d05e4 + ? ./unpackOptionals.dhall +, unzip = + missing + sha256:4d6003e9e683a289fe33f4c90f958eb1e08ea0bbb474210fcd90d1885c9660e9 + ? ./unzip.dhall +, zip = + missing + sha256:85ed955eabf3998767f4ad2a28e57d40cd4c68a95519d79e9b622f1d26d979da + ? ./zip.dhall +} diff --git a/dhall/Prelude/List/partition b/dhall/Prelude/List/partition new file mode 100644 index 0000000..5454f31 --- /dev/null +++ b/dhall/Prelude/List/partition @@ -0,0 +1,3 @@ + missing + sha256:38147ac6d750a6492736dd90cc967bf09aa405c499de943c64fab7b86ae02f03 +? ./partition.dhall diff --git a/dhall/Prelude/List/partition.dhall b/dhall/Prelude/List/partition.dhall new file mode 100644 index 0000000..d38ebae --- /dev/null +++ b/dhall/Prelude/List/partition.dhall @@ -0,0 +1,31 @@ +{-| +`partition` divides a `List` of elements into those that satisfy a predicate +and those that do not +-} +let Partition + : Type → Type + = λ(a : Type) → { true : List a, false : List a } + +let partition + : ∀(a : Type) → (a → Bool) → List a → Partition a + = λ(a : Type) → + λ(f : a → Bool) → + λ(xs : List a) → + List/fold + a + xs + (Partition a) + ( λ(x : a) → + λ(p : Partition a) → + if f x + then { true = [ x ] # p.true, false = p.false } + else { true = p.true, false = [ x ] # p.false } + ) + { true = [] : List a, false = [] : List a } + +let example0 = + assert + : partition Natural Natural/even [ 0, 1, 2, 3 ] + ≡ { true = [ 0, 2 ], false = [ 1, 3 ] } + +in partition diff --git a/dhall/Prelude/List/replicate b/dhall/Prelude/List/replicate new file mode 100644 index 0000000..6578bfa --- /dev/null +++ b/dhall/Prelude/List/replicate @@ -0,0 +1,3 @@ + missing + sha256:d4250b45278f2d692302489ac3e78280acb238d27541c837ce46911ff3baa347 +? ./replicate.dhall diff --git a/dhall/Prelude/List/replicate.dhall b/dhall/Prelude/List/replicate.dhall new file mode 100644 index 0000000..90bfbd0 --- /dev/null +++ b/dhall/Prelude/List/replicate.dhall @@ -0,0 +1,18 @@ +--| Build a list by copying the given element the specified number of times +let replicate + : Natural → ∀(a : Type) → a → List a + = λ(n : Natural) → + λ(a : Type) → + λ(x : a) → + List/build + a + ( λ(list : Type) → + λ(cons : a → list → list) → + Natural/fold n list (cons x) + ) + +let example0 = assert : replicate 9 Natural 1 ≡ [ 1, 1, 1, 1, 1, 1, 1, 1, 1 ] + +let example1 = assert : replicate 0 Natural 1 ≡ ([] : List Natural) + +in replicate diff --git a/dhall/Prelude/List/reverse b/dhall/Prelude/List/reverse new file mode 100644 index 0000000..af355dc --- /dev/null +++ b/dhall/Prelude/List/reverse @@ -0,0 +1,3 @@ + missing + sha256:ad99d224d61852de6696da5a7d04c98dbe676fe67d5e4ef4f19e9aaa27006e9d +? ./reverse.dhall diff --git a/dhall/Prelude/List/reverse.dhall b/dhall/Prelude/List/reverse.dhall new file mode 100644 index 0000000..d958987 --- /dev/null +++ b/dhall/Prelude/List/reverse.dhall @@ -0,0 +1,11 @@ +--| Reverse a list +let reverse + : ∀(a : Type) → List a → List a + = List/reverse + +let example0 = assert : reverse Natural [ 0, 1, 2 ] ≡ [ 2, 1, 0 ] + +let example1 = + assert : reverse Natural ([] : List Natural) ≡ ([] : List Natural) + +in reverse diff --git a/dhall/Prelude/List/shifted b/dhall/Prelude/List/shifted new file mode 100644 index 0000000..73db290 --- /dev/null +++ b/dhall/Prelude/List/shifted @@ -0,0 +1,3 @@ + missing + sha256:54fb22c7e952ebce1cfc0fcdd33ce4cfa817bff9d6564af268dea6685f8b5dfe +? ./shifted.dhall diff --git a/dhall/Prelude/List/shifted.dhall b/dhall/Prelude/List/shifted.dhall new file mode 100644 index 0000000..0db406d --- /dev/null +++ b/dhall/Prelude/List/shifted.dhall @@ -0,0 +1,83 @@ +{-| +Combine a `List` of `List`s, offsetting the `index` of each element by the +number of elements in preceding lists +-} +let shifted + : ∀(a : Type) → + List (List { index : Natural, value : a }) → + List { index : Natural, value : a } + = λ(a : Type) → + λ(kvss : List (List { index : Natural, value : a })) → + List/build + { index : Natural, value : a } + ( λ(list : Type) → + λ(cons : { index : Natural, value : a } → list → list) → + λ(nil : list) → + let result = + List/fold + (List { index : Natural, value : a }) + kvss + { count : Natural, diff : Natural → list } + ( λ(kvs : List { index : Natural, value : a }) → + λ(y : { count : Natural, diff : Natural → list }) → + let length = + List/length { index : Natural, value : a } kvs + + in { count = y.count + length + , diff = + λ(n : Natural) → + List/fold + { index : Natural, value : a } + kvs + list + ( λ ( kvOld + : { index : Natural, value : a } + ) → + λ(z : list) → + let kvNew = + { index = kvOld.index + n + , value = kvOld.value + } + + in cons kvNew z + ) + (y.diff (n + length)) + } + ) + { count = 0, diff = λ(_ : Natural) → nil } + + in result.diff 0 + ) + +let example0 = + assert + : shifted + Bool + [ [ { index = 0, value = True } + , { index = 1, value = True } + , { index = 2, value = True } + ] + , [ { index = 0, value = False }, { index = 1, value = False } ] + , [ { index = 0, value = True } + , { index = 1, value = True } + , { index = 2, value = True } + , { index = 3, value = True } + ] + ] + ≡ [ { index = 0, value = True } + , { index = 1, value = True } + , { index = 2, value = True } + , { index = 3, value = False } + , { index = 4, value = False } + , { index = 5, value = True } + , { index = 6, value = True } + , { index = 7, value = True } + , { index = 8, value = True } + ] + +let example1 = + assert + : shifted Bool ([] : List (List { index : Natural, value : Bool })) + ≡ ([] : List { index : Natural, value : Bool }) + +in shifted diff --git a/dhall/Prelude/List/take b/dhall/Prelude/List/take new file mode 100644 index 0000000..55f1ac3 --- /dev/null +++ b/dhall/Prelude/List/take @@ -0,0 +1,3 @@ + missing + sha256:b3e08ee8c3a5bf3d8ccee6b2b2008fbb8e51e7373aef6f1af67ad10078c9fbfa +? ./take.dhall diff --git a/dhall/Prelude/List/take.dhall b/dhall/Prelude/List/take.dhall new file mode 100644 index 0000000..634dbae --- /dev/null +++ b/dhall/Prelude/List/take.dhall @@ -0,0 +1,26 @@ +--| Truncate a list to the first `n` elements +let Natural/lessThan = + missing + sha256:3381b66749290769badf8855d8a3f4af62e8de52d1364d838a9d1e20c94fa70c + ? ../Natural/lessThan.dhall + +let take + : ∀(n : Natural) → ∀(a : Type) → List a → List a + = λ(n : Natural) → + λ(a : Type) → + λ(xs : List a) → + List/fold + { index : Natural, value : a } + (List/indexed a xs) + (List a) + ( λ(x : { index : Natural, value : a }) → + λ(xs : List a) → + if Natural/lessThan x.index n then [ x.value ] # xs else xs + ) + ([] : List a) + +let example = assert : take 2 Natural [ 2, 3, 5 ] ≡ [ 2, 3 ] + +let example = assert : take 5 Natural [ 2, 3, 5 ] ≡ [ 2, 3, 5 ] + +in take diff --git a/dhall/Prelude/List/unpackOptionals b/dhall/Prelude/List/unpackOptionals new file mode 100644 index 0000000..1cf9891 --- /dev/null +++ b/dhall/Prelude/List/unpackOptionals @@ -0,0 +1,3 @@ + missing + sha256:0cbaa920f429cf7fc3907f8a9143203fe948883913560e6e1043223e6b3d05e4 +? ./unpackOptionals.dhall diff --git a/dhall/Prelude/List/unpackOptionals.dhall b/dhall/Prelude/List/unpackOptionals.dhall new file mode 100644 index 0000000..105d546 --- /dev/null +++ b/dhall/Prelude/List/unpackOptionals.dhall @@ -0,0 +1,31 @@ +--| Unpack Optionals in a List, omitting None items. +let List/filterMap = + missing + sha256:94b7ed4204d1c79aaf55527ef51024e7085b8dd2896952cffbd12d8f95e16f46 + ? ./filterMap.dhall + +let unpackOptionals + : ∀(a : Type) → ∀(l : List (Optional a)) → List a + = λ(a : Type) → List/filterMap (Optional a) a (λ(x : Optional a) → x) + +let property1 = + λ(a : Type) → λ(x : a) → assert : unpackOptionals a [ Some x ] ≡ [ x ] + +let property2 = + λ(a : Type) → assert : unpackOptionals a [ None a ] ≡ ([] : List a) + +let example0 = + assert + : unpackOptionals Natural [ Some 1, None Natural, Some 3 ] ≡ [ 1, 3 ] + +let example1 = + assert + : unpackOptionals Natural ([] : List (Optional Natural)) + ≡ ([] : List Natural) + +let example2 = + assert + : unpackOptionals Natural [ None Natural, None Natural ] + ≡ ([] : List Natural) + +in unpackOptionals diff --git a/dhall/Prelude/List/unzip b/dhall/Prelude/List/unzip new file mode 100644 index 0000000..549a802 --- /dev/null +++ b/dhall/Prelude/List/unzip @@ -0,0 +1,3 @@ + missing + sha256:4d6003e9e683a289fe33f4c90f958eb1e08ea0bbb474210fcd90d1885c9660e9 +? ./unzip.dhall diff --git a/dhall/Prelude/List/unzip.dhall b/dhall/Prelude/List/unzip.dhall new file mode 100644 index 0000000..3ce4f76 --- /dev/null +++ b/dhall/Prelude/List/unzip.dhall @@ -0,0 +1,50 @@ +--| Unzip a `List` into two separate `List`s +let unzip + : ∀(a : Type) → + ∀(b : Type) → + List { _1 : a, _2 : b } → + { _1 : List a, _2 : List b } + = λ(a : Type) → + λ(b : Type) → + λ(xs : List { _1 : a, _2 : b }) → + { _1 = + List/build + a + ( λ(list : Type) → + λ(cons : a → list → list) → + List/fold + { _1 : a, _2 : b } + xs + list + (λ(x : { _1 : a, _2 : b }) → cons x._1) + ) + , _2 = + List/build + b + ( λ(list : Type) → + λ(cons : b → list → list) → + List/fold + { _1 : a, _2 : b } + xs + list + (λ(x : { _1 : a, _2 : b }) → cons x._2) + ) + } + +let example0 = + assert + : unzip + Text + Bool + [ { _1 = "ABC", _2 = True } + , { _1 = "DEF", _2 = False } + , { _1 = "GHI", _2 = True } + ] + ≡ { _1 = [ "ABC", "DEF", "GHI" ], _2 = [ True, False, True ] } + +let example1 = + assert + : unzip Text Bool ([] : List { _1 : Text, _2 : Bool }) + ≡ { _1 = [] : List Text, _2 = [] : List Bool } + +in unzip diff --git a/dhall/Prelude/List/zip b/dhall/Prelude/List/zip new file mode 100644 index 0000000..fcf0a9f --- /dev/null +++ b/dhall/Prelude/List/zip @@ -0,0 +1,3 @@ + missing + sha256:85ed955eabf3998767f4ad2a28e57d40cd4c68a95519d79e9b622f1d26d979da +? ./zip.dhall diff --git a/dhall/Prelude/List/zip.dhall b/dhall/Prelude/List/zip.dhall new file mode 100644 index 0000000..9066403 --- /dev/null +++ b/dhall/Prelude/List/zip.dhall @@ -0,0 +1,58 @@ +{-| +Zip two `List` into a single `List` + +The resulting `List` will have the length of the shortest of its arguments. +-} +let List/index = + missing + sha256:e657b55ecae4d899465c3032cb1a64c6aa6dc2aa3034204f3c15ce5c96c03e63 + ? ./index.dhall + +let zip + : ∀(a : Type) → List a → ∀(b : Type) → List b → List { _1 : a, _2 : b } + = λ(a : Type) → + λ(xs : List a) → + λ(b : Type) → + λ(ys : List b) → + let ixs = List/indexed a xs + + in List/build + { _1 : a, _2 : b } + ( λ(list : Type) → + λ(cons : { _1 : a, _2 : b } → list → list) → + λ(nil : list) → + List/fold + { index : Natural, value : a } + ixs + list + ( λ(ix : { index : Natural, value : a }) → + λ(rest : list) → + merge + { None = rest + , Some = + λ(y : b) → cons { _1 = ix.value, _2 = y } rest + } + (List/index ix.index b ys) + ) + nil + ) + +let example0 = + assert + : zip Text [ "ABC", "DEF", "GHI" ] Natural [ 1, 2, 3 ] + ≡ [ { _1 = "ABC", _2 = 1 } + , { _1 = "DEF", _2 = 2 } + , { _1 = "GHI", _2 = 3 } + ] + +let example1 = + assert + : zip Text [ "ABC" ] Bool ([] : List Bool) + ≡ ([] : List { _1 : Text, _2 : Bool }) + +let example2 = + assert + : zip Text [ "ABC", "DEF", "GHI" ] Natural [ 1 ] + ≡ [ { _1 = "ABC", _2 = 1 } ] + +in zip diff --git a/dhall/Prelude/Location/Type b/dhall/Prelude/Location/Type new file mode 100644 index 0000000..b511a9a --- /dev/null +++ b/dhall/Prelude/Location/Type @@ -0,0 +1,3 @@ + missing + sha256:613ebb491aeef4ff06368058b4f0e6e3bb8a58d8c145131fc0b947aac045a529 +? ./Type.dhall diff --git a/dhall/Prelude/Location/Type.dhall b/dhall/Prelude/Location/Type.dhall new file mode 100644 index 0000000..6e2bdf3 --- /dev/null +++ b/dhall/Prelude/Location/Type.dhall @@ -0,0 +1,15 @@ +--| This is the union type returned when you import something `as Location` +let Location + : Type + = < Environment : Text | Local : Text | Missing | Remote : Text > + +let example0 = + assert + : missing as Location + ≡ < Environment : Text + | Local : Text + | Missing + | Remote : Text + >.Missing + +in Location diff --git a/dhall/Prelude/Location/package.dhall b/dhall/Prelude/Location/package.dhall new file mode 100644 index 0000000..6eecfb0 --- /dev/null +++ b/dhall/Prelude/Location/package.dhall @@ -0,0 +1,5 @@ +{ Type = + missing + sha256:613ebb491aeef4ff06368058b4f0e6e3bb8a58d8c145131fc0b947aac045a529 + ? ./Type.dhall +} diff --git a/dhall/Prelude/Map/Entry b/dhall/Prelude/Map/Entry new file mode 100644 index 0000000..9a54d98 --- /dev/null +++ b/dhall/Prelude/Map/Entry @@ -0,0 +1,3 @@ + missing + sha256:f334283bdd9cd88e6ea510ca914bc221fc2dab5fb424d24514b2e0df600d5346 +? ./Entry.dhall diff --git a/dhall/Prelude/Map/Entry.dhall b/dhall/Prelude/Map/Entry.dhall new file mode 100644 index 0000000..16d02f9 --- /dev/null +++ b/dhall/Prelude/Map/Entry.dhall @@ -0,0 +1,6 @@ +--| The type of each key-value pair in a `Map` +let Entry + : Type → Type → Type + = λ(k : Type) → λ(v : Type) → { mapKey : k, mapValue : v } + +in Entry diff --git a/dhall/Prelude/Map/Type b/dhall/Prelude/Map/Type new file mode 100644 index 0000000..1c642aa --- /dev/null +++ b/dhall/Prelude/Map/Type @@ -0,0 +1,3 @@ + missing + sha256:210c7a9eba71efbb0f7a66b3dcf8b9d3976ffc2bc0e907aadfb6aa29c333e8ed +? ./Type.dhall diff --git a/dhall/Prelude/Map/Type.dhall b/dhall/Prelude/Map/Type.dhall new file mode 100644 index 0000000..7118c3b --- /dev/null +++ b/dhall/Prelude/Map/Type.dhall @@ -0,0 +1,25 @@ +{-| +This is the canonical way to encode a dynamic list of key-value pairs. + +Tools (such as `dhall-to-json`/`dhall-to-yaml` will recognize values of this +type and convert them to maps/dictionaries/hashes in the target language + +For example, `dhall-to-json` converts a Dhall value like this: + +``` +[ { mapKey = "foo", mapValue = 1 } +, { mapKey = "bar", mapValue = 2 } +] : ./Map Text Natural +``` + +... to a JSON value like this: + +``` +{ "foo": 1, "bar", 2 } +``` +-} +let Map + : Type → Type → Type + = λ(k : Type) → λ(v : Type) → List { mapKey : k, mapValue : v } + +in Map diff --git a/dhall/Prelude/Map/empty b/dhall/Prelude/Map/empty new file mode 100644 index 0000000..9321c31 --- /dev/null +++ b/dhall/Prelude/Map/empty @@ -0,0 +1,3 @@ + missing + sha256:4c612558b8bbe8f955550ed3fb295d57b1b864c85cd52615b52d0ee0e9682e52 +? ./empty.dhall diff --git a/dhall/Prelude/Map/empty.dhall b/dhall/Prelude/Map/empty.dhall new file mode 100644 index 0000000..dc135ed --- /dev/null +++ b/dhall/Prelude/Map/empty.dhall @@ -0,0 +1,14 @@ +--| An empty `Map` of the given key and value types +let Map = + missing + sha256:210c7a9eba71efbb0f7a66b3dcf8b9d3976ffc2bc0e907aadfb6aa29c333e8ed + ? ./Type.dhall + +let empty + : ∀(k : Type) → ∀(v : Type) → Map k v + = λ(k : Type) → λ(v : Type) → [] : Map k v + +let example0 = + assert : empty Text Bool ≡ ([] : List { mapKey : Text, mapValue : Bool }) + +in empty diff --git a/dhall/Prelude/Map/keyText b/dhall/Prelude/Map/keyText new file mode 100644 index 0000000..8710683 --- /dev/null +++ b/dhall/Prelude/Map/keyText @@ -0,0 +1,3 @@ + missing + sha256:f7b6c802ca5764d03d5e9a6e48d9cb167c01392f775d9c2c87b83cdaa60ea0cc +? ./keyText.dhall diff --git a/dhall/Prelude/Map/keyText.dhall b/dhall/Prelude/Map/keyText.dhall new file mode 100644 index 0000000..0e9a223 --- /dev/null +++ b/dhall/Prelude/Map/keyText.dhall @@ -0,0 +1,15 @@ +{-| +Builds a key-value record such that a `List` of them will be converted to a +homogeneous record by dhall-to-json and dhall-to-yaml. + +Both key and value are fixed to `Text`. + +Take a look at `./keyValue` for a polymorphic version. +-} +let keyText = + λ(key : Text) → λ(value : Text) → { mapKey = key, mapValue = value } + +let example0 = + assert : keyText "foo" "bar" ≡ { mapKey = "foo", mapValue = "bar" } + +in keyText diff --git a/dhall/Prelude/Map/keyValue b/dhall/Prelude/Map/keyValue new file mode 100644 index 0000000..d762d37 --- /dev/null +++ b/dhall/Prelude/Map/keyValue @@ -0,0 +1,3 @@ + missing + sha256:a0a97199d280c4cce72ffcbbf93b7ceda0a569cf4d173ac98e0aaaa78034b98c +? ./keyValue.dhall diff --git a/dhall/Prelude/Map/keyValue.dhall b/dhall/Prelude/Map/keyValue.dhall new file mode 100644 index 0000000..b7d60cb --- /dev/null +++ b/dhall/Prelude/Map/keyValue.dhall @@ -0,0 +1,17 @@ +{-| +Builds a key-value record such that a List of them will be converted to a +homogeneous record by dhall-to-json and dhall-to-yaml. +-} +let keyValue = + λ(v : Type) → + λ(key : Text) → + λ(value : v) → + { mapKey = key, mapValue = value } + +let example0 = + assert : keyValue Natural "foo" 2 ≡ { mapKey = "foo", mapValue = 2 } + +let example1 = + assert : keyValue Text "bar" "baz" ≡ { mapKey = "bar", mapValue = "baz" } + +in keyValue diff --git a/dhall/Prelude/Map/keys b/dhall/Prelude/Map/keys new file mode 100644 index 0000000..7c08e26 --- /dev/null +++ b/dhall/Prelude/Map/keys @@ -0,0 +1,3 @@ + missing + sha256:d13ec34e6acf7c349d82272ef09a37c7bdf37f0dab489e9df47a1ff215d9f5e7 +? ./keys.dhall diff --git a/dhall/Prelude/Map/keys.dhall b/dhall/Prelude/Map/keys.dhall new file mode 100644 index 0000000..27f5c3c --- /dev/null +++ b/dhall/Prelude/Map/keys.dhall @@ -0,0 +1,39 @@ +--| Get all of the keys of a `Map` as a `List` +let Map = + missing + sha256:210c7a9eba71efbb0f7a66b3dcf8b9d3976ffc2bc0e907aadfb6aa29c333e8ed + ? ./Type.dhall + +let Entry = + missing + sha256:f334283bdd9cd88e6ea510ca914bc221fc2dab5fb424d24514b2e0df600d5346 + ? ./Entry.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map + +let keys + : ∀(k : Type) → ∀(v : Type) → Map k v → List k + = λ(k : Type) → + λ(v : Type) → + List/map (Entry k v) k (λ(x : Entry k v) → x.mapKey) + +let example0 = + assert + : keys + Text + Natural + [ { mapKey = "A", mapValue = 2 } + , { mapKey = "B", mapValue = 3 } + , { mapKey = "C", mapValue = 5 } + ] + ≡ [ "A", "B", "C" ] + +let example1 = + assert + : keys Text Natural ([] : List { mapKey : Text, mapValue : Natural }) + ≡ ([] : List Text) + +in keys diff --git a/dhall/Prelude/Map/map b/dhall/Prelude/Map/map new file mode 100644 index 0000000..077bfa5 --- /dev/null +++ b/dhall/Prelude/Map/map @@ -0,0 +1,3 @@ + missing + sha256:23e09b0b9f08649797dfe1ca39755d5e1c7cad2d0944bdd36c7a0bf804bde8d0 +? ./map.dhall diff --git a/dhall/Prelude/Map/map.dhall b/dhall/Prelude/Map/map.dhall new file mode 100644 index 0000000..27b45d0 --- /dev/null +++ b/dhall/Prelude/Map/map.dhall @@ -0,0 +1,58 @@ +--| Transform a `Map` by applying a function to each value +let Map = + missing + sha256:210c7a9eba71efbb0f7a66b3dcf8b9d3976ffc2bc0e907aadfb6aa29c333e8ed + ? ./Type.dhall + +let Entry = + missing + sha256:f334283bdd9cd88e6ea510ca914bc221fc2dab5fb424d24514b2e0df600d5346 + ? ./Entry.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map.dhall + +let map + : ∀(k : Type) → ∀(a : Type) → ∀(b : Type) → (a → b) → Map k a → Map k b + = λ(k : Type) → + λ(a : Type) → + λ(b : Type) → + λ(f : a → b) → + λ(m : Map k a) → + List/map + (Entry k a) + (Entry k b) + ( λ(before : Entry k a) → + { mapKey = before.mapKey, mapValue = f before.mapValue } + ) + m + +let example0 = + assert + : map + Text + Natural + Bool + Natural/even + [ { mapKey = "A", mapValue = 2 } + , { mapKey = "B", mapValue = 3 } + , { mapKey = "C", mapValue = 5 } + ] + ≡ [ { mapKey = "A", mapValue = True } + , { mapKey = "B", mapValue = False } + , { mapKey = "C", mapValue = False } + ] + +let example1 = + assert + : map + Text + Natural + Bool + Natural/even + ([] : List { mapKey : Text, mapValue : Natural }) + ≡ ([] : List { mapKey : Text, mapValue : Bool }) + +in map diff --git a/dhall/Prelude/Map/mapMaybe.dhall b/dhall/Prelude/Map/mapMaybe.dhall new file mode 100644 index 0000000..829e802 --- /dev/null +++ b/dhall/Prelude/Map/mapMaybe.dhall @@ -0,0 +1,56 @@ +--| Apply a function across the values of a `Map k v`, dropping +-- entries whose values return `None`. +let Map/empty = + missing + sha256:4c612558b8bbe8f955550ed3fb295d57b1b864c85cd52615b52d0ee0e9682e52 + ? ./empty.dhall + +let Map/unpackOptionals = + missing + sha256:66c3e6f6f81418cf99342e1dba739617c01af4b27c1ca5e2e1d7bce64a522e22 + ? ./unpackOptionals.dhall + +let Map/map = + missing + sha256:23e09b0b9f08649797dfe1ca39755d5e1c7cad2d0944bdd36c7a0bf804bde8d0 + ? ./map.dhall + +let Map/Type = + missing + sha256:210c7a9eba71efbb0f7a66b3dcf8b9d3976ffc2bc0e907aadfb6aa29c333e8ed + ? ./Type.dhall + +let mapMaybe + : ∀(k : Type) → + ∀(a : Type) → + ∀(b : Type) → + (a → Optional b) → + Map/Type k a → + Map/Type k b + = λ(k : Type) → + λ(a : Type) → + λ(b : Type) → + λ(f : a → Optional b) → + λ(m : Map/Type k a) → + Map/unpackOptionals k b (Map/map k a (Optional b) f m) + +let property = + λ(k : Type) → + λ(a : Type) → + λ(b : Type) → + λ(f : a → Optional b) → + assert : mapMaybe k a b f (Map/empty k a) ≡ Map/empty k b + +let example0 = + assert + : mapMaybe + Text + Natural + Text + ( λ(n : Natural) → + if Natural/isZero n then None Text else Some (Natural/show n) + ) + (toMap { foo = 2, bar = 0 }) + ≡ toMap { foo = "2" } + +in mapMaybe diff --git a/dhall/Prelude/Map/package.dhall b/dhall/Prelude/Map/package.dhall new file mode 100644 index 0000000..4bc955c --- /dev/null +++ b/dhall/Prelude/Map/package.dhall @@ -0,0 +1,41 @@ +{ Type = + missing + sha256:210c7a9eba71efbb0f7a66b3dcf8b9d3976ffc2bc0e907aadfb6aa29c333e8ed + ? ./Type +, Entry = + missing + sha256:f334283bdd9cd88e6ea510ca914bc221fc2dab5fb424d24514b2e0df600d5346 + ? ./Entry +, empty = + missing + sha256:4c612558b8bbe8f955550ed3fb295d57b1b864c85cd52615b52d0ee0e9682e52 + ? ./empty +, keyText = + missing + sha256:f7b6c802ca5764d03d5e9a6e48d9cb167c01392f775d9c2c87b83cdaa60ea0cc + ? ./keyText +, keyValue = + missing + sha256:a0a97199d280c4cce72ffcbbf93b7ceda0a569cf4d173ac98e0aaaa78034b98c + ? ./keyValue +, keys = + missing + sha256:d13ec34e6acf7c349d82272ef09a37c7bdf37f0dab489e9df47a1ff215d9f5e7 + ? ./keys +, map = + missing + sha256:23e09b0b9f08649797dfe1ca39755d5e1c7cad2d0944bdd36c7a0bf804bde8d0 + ? ./map +, mapMaybe = + missing + sha256:4ea58b720d7af38cef3ef07bef36e476caeed21032cd4a9dc733868a74d9a521 + ? ./mapMaybe.dhall +, unpackOptionals = + missing + sha256:66c3e6f6f81418cf99342e1dba739617c01af4b27c1ca5e2e1d7bce64a522e22 + ? ./unpackOptionals.dhall +, values = + missing + sha256:ae02cfb06a9307cbecc06130e84fd0c7b96b7f1f11648961e1b030ec00940be8 + ? ./values +} diff --git a/dhall/Prelude/Map/unpackOptionals.dhall b/dhall/Prelude/Map/unpackOptionals.dhall new file mode 100644 index 0000000..c17a091 --- /dev/null +++ b/dhall/Prelude/Map/unpackOptionals.dhall @@ -0,0 +1,41 @@ +--| Turn a `Map k (Optional v)` into a `Map k v` by dropping all +-- entries with value `None`. +let List/concatMap = + missing + sha256:3b2167061d11fda1e4f6de0522cbe83e0d5ac4ef5ddf6bb0b2064470c5d3fb64 + ? ../List/concatMap.dhall + +let Map/Entry = + missing + sha256:f334283bdd9cd88e6ea510ca914bc221fc2dab5fb424d24514b2e0df600d5346 + ? ./Entry.dhall + +let Map/Type = + missing + sha256:210c7a9eba71efbb0f7a66b3dcf8b9d3976ffc2bc0e907aadfb6aa29c333e8ed + ? ./Type.dhall + +let unpackOptionals + : ∀(k : Type) → ∀(v : Type) → Map/Type k (Optional v) → Map/Type k v + = λ(k : Type) → + λ(v : Type) → + List/concatMap + (Map/Entry k (Optional v)) + (Map/Entry k v) + ( λ(e : Map/Entry k (Optional v)) → + merge + { None = [] : Map/Type k v + , Some = λ(v : v) → [ { mapKey = e.mapKey, mapValue = v } ] + } + e.mapValue + ) + +let example0 = + assert + : unpackOptionals + Text + Text + (toMap { foo = Some "bar", baz = None Text }) + ≡ toMap { foo = "bar" } + +in unpackOptionals diff --git a/dhall/Prelude/Map/values b/dhall/Prelude/Map/values new file mode 100644 index 0000000..9163792 --- /dev/null +++ b/dhall/Prelude/Map/values @@ -0,0 +1,3 @@ + missing + sha256:ae02cfb06a9307cbecc06130e84fd0c7b96b7f1f11648961e1b030ec00940be8 +? ./values.dhall diff --git a/dhall/Prelude/Map/values.dhall b/dhall/Prelude/Map/values.dhall new file mode 100644 index 0000000..3b65c20 --- /dev/null +++ b/dhall/Prelude/Map/values.dhall @@ -0,0 +1,39 @@ +--| Get all of the values of a `Map` as a `List` +let Map = + missing + sha256:210c7a9eba71efbb0f7a66b3dcf8b9d3976ffc2bc0e907aadfb6aa29c333e8ed + ? ./Type.dhall + +let Entry = + missing + sha256:f334283bdd9cd88e6ea510ca914bc221fc2dab5fb424d24514b2e0df600d5346 + ? ./Entry.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map.dhall + +let values + : ∀(k : Type) → ∀(v : Type) → Map k v → List v + = λ(k : Type) → + λ(v : Type) → + List/map (Entry k v) v (λ(x : Entry k v) → x.mapValue) + +let example0 = + assert + : values + Text + Natural + [ { mapKey = "A", mapValue = 2 } + , { mapKey = "B", mapValue = 3 } + , { mapKey = "C", mapValue = 5 } + ] + ≡ [ 2, 3, 5 ] + +let example1 = + assert + : values Text Natural ([] : List { mapKey : Text, mapValue : Natural }) + ≡ ([] : List Natural) + +in values diff --git a/dhall/Prelude/Monoid b/dhall/Prelude/Monoid new file mode 100644 index 0000000..dc551b9 --- /dev/null +++ b/dhall/Prelude/Monoid @@ -0,0 +1,3 @@ + missing + sha256:26fafa098600ef7a54ef9dba5ada416bbbdd21df1af306c052420c61553ad4af +? ./Monoid.dhall diff --git a/dhall/Prelude/Monoid.dhall b/dhall/Prelude/Monoid.dhall new file mode 100644 index 0000000..e52d8f1 --- /dev/null +++ b/dhall/Prelude/Monoid.dhall @@ -0,0 +1,43 @@ +{-| +Any function `f` that is a `Monoid` must satisfy the following law: + +``` +t : Type +f : ./Monoid t +xs : List (List t) + +f (./List/concat t xs) = f (./map (List t) t f xs) +``` + +Examples: + +``` +./Bool/and + : ./Monoid Bool +./Bool/or + : ./Monoid Bool +./Bool/even + : ./Monoid Bool +./Bool/odd + : ./Monoid Bool +./List/concat + : ∀(a : Type) → ./Monoid (List a) +./List/shifted + : ∀(a : Type) → ./Monoid (List { index : Natural, value : a }) +./Natural/sum + : ./Monoid Natural +./Natural/product + : ./Monoid Natural +./Optional/head + : ∀(a : Type) → ./Monoid (Optional a) +./Optional/last + : ∀(a : Type) → ./Monoid (Optional a) +./Text/concat + : ./Monoid Text +``` +-} +let Monoid + : ∀(m : Type) → Type + = λ(m : Type) → List m → m + +in Monoid diff --git a/dhall/Prelude/Natural/build b/dhall/Prelude/Natural/build new file mode 100644 index 0000000..89306e3 --- /dev/null +++ b/dhall/Prelude/Natural/build @@ -0,0 +1,3 @@ + missing + sha256:e7e25e6c4f1d8e573606ed1bef725396ac2de5c68f7c5d329ffc5822085b984c +? ./build.dhall diff --git a/dhall/Prelude/Natural/build.dhall b/dhall/Prelude/Natural/build.dhall new file mode 100644 index 0000000..f09ac2c --- /dev/null +++ b/dhall/Prelude/Natural/build.dhall @@ -0,0 +1,31 @@ +--| `build` is the inverse of `fold` +let build + : ( ∀(natural : Type) → + ∀(succ : natural → natural) → + ∀(zero : natural) → + natural + ) → + Natural + = Natural/build + +let example0 = + assert + : build + ( λ(natural : Type) → + λ(succ : natural → natural) → + λ(zero : natural) → + succ (succ (succ zero)) + ) + ≡ 3 + +let example1 = + assert + : build + ( λ(natural : Type) → + λ(succ : natural → natural) → + λ(zero : natural) → + zero + ) + ≡ 0 + +in build diff --git a/dhall/Prelude/Natural/enumerate b/dhall/Prelude/Natural/enumerate new file mode 100644 index 0000000..04644a1 --- /dev/null +++ b/dhall/Prelude/Natural/enumerate @@ -0,0 +1,3 @@ + missing + sha256:0cf083980a752b21ce0df9fc2222a4c139f50909e2353576e26a191002aa1ce3 +? ./enumerate.dhall diff --git a/dhall/Prelude/Natural/enumerate.dhall b/dhall/Prelude/Natural/enumerate.dhall new file mode 100644 index 0000000..de86110 --- /dev/null +++ b/dhall/Prelude/Natural/enumerate.dhall @@ -0,0 +1,32 @@ +{-| +Generate a list of numbers from `0` up to but not including the specified +number +-} +let enumerate + : Natural → List Natural + = λ(n : Natural) → + List/build + Natural + ( λ(list : Type) → + λ(cons : Natural → list → list) → + List/fold + { index : Natural, value : {} } + ( List/indexed + {} + ( List/build + {} + ( λ(list : Type) → + λ(cons : {} → list → list) → + Natural/fold n list (cons {=}) + ) + ) + ) + list + (λ(x : { index : Natural, value : {} }) → cons x.index) + ) + +let example0 = assert : enumerate 10 ≡ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] + +let example1 = assert : enumerate 0 ≡ ([] : List Natural) + +in enumerate diff --git a/dhall/Prelude/Natural/equal b/dhall/Prelude/Natural/equal new file mode 100644 index 0000000..e3385cf --- /dev/null +++ b/dhall/Prelude/Natural/equal @@ -0,0 +1,3 @@ + missing + sha256:7f108edfa35ddc7cebafb24dc073478e93a802e13b5bc3fd22f4768c9b066e60 +? ./equal.dhall diff --git a/dhall/Prelude/Natural/equal.dhall b/dhall/Prelude/Natural/equal.dhall new file mode 100644 index 0000000..ad728df --- /dev/null +++ b/dhall/Prelude/Natural/equal.dhall @@ -0,0 +1,17 @@ +--| `equal` checks if two Naturals are equal. +let lessThanEqual = + missing + sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 + ? ./lessThanEqual.dhall + +let equal + : Natural → Natural → Bool + = λ(a : Natural) → λ(b : Natural) → lessThanEqual a b && lessThanEqual b a + +let example0 = assert : equal 5 5 ≡ True + +let example1 = assert : equal 5 6 ≡ False + +let property0 = λ(n : Natural) → assert : equal n n ≡ True + +in equal diff --git a/dhall/Prelude/Natural/even b/dhall/Prelude/Natural/even new file mode 100644 index 0000000..97c45c3 --- /dev/null +++ b/dhall/Prelude/Natural/even @@ -0,0 +1,3 @@ + missing + sha256:b85b8b56892dfef881e1c0e79eade0b949528f792aac0ea42432b315ede4ee66 +? ./even.dhall diff --git a/dhall/Prelude/Natural/even.dhall b/dhall/Prelude/Natural/even.dhall new file mode 100644 index 0000000..d65cad1 --- /dev/null +++ b/dhall/Prelude/Natural/even.dhall @@ -0,0 +1,10 @@ +--| Returns `True` if a number if even and returns `False` otherwise +let even + : Natural → Bool + = Natural/even + +let example0 = assert : even 3 ≡ False + +let example1 = assert : even 0 ≡ True + +in even diff --git a/dhall/Prelude/Natural/fold b/dhall/Prelude/Natural/fold new file mode 100644 index 0000000..5ab6ae4 --- /dev/null +++ b/dhall/Prelude/Natural/fold @@ -0,0 +1,3 @@ + missing + sha256:fd01c931e585a8f5fd049af7b076b862ea164f1813b34800c7616a49e549ee06 +? ./fold.dhall diff --git a/dhall/Prelude/Natural/fold.dhall b/dhall/Prelude/Natural/fold.dhall new file mode 100644 index 0000000..4f6dd03 --- /dev/null +++ b/dhall/Prelude/Natural/fold.dhall @@ -0,0 +1,28 @@ +{-| +`fold` is the primitive function for consuming `Natural` numbers + +If you treat the number `3` as `succ (succ (succ zero))` then a `fold` just +replaces each `succ` and `zero` with something else +-} +let fold + : Natural → + ∀(natural : Type) → + ∀(succ : natural → natural) → + ∀(zero : natural) → + natural + = Natural/fold + +let example0 = assert : fold 3 Text (λ(x : Text) → "A" ++ x) "B" ≡ "AAAB" + +let example1 = + λ(zero : Text) → + assert + : fold 3 Text (λ(x : Text) → "A" ++ x) zero + ≡ "A" ++ ("A" ++ ("A" ++ zero)) + +let example2 = + λ(succ : Text → Text) → + λ(zero : Text) → + assert : fold 3 Text succ zero ≡ succ (succ (succ zero)) + +in fold diff --git a/dhall/Prelude/Natural/greaterThan b/dhall/Prelude/Natural/greaterThan new file mode 100644 index 0000000..eb29db8 --- /dev/null +++ b/dhall/Prelude/Natural/greaterThan @@ -0,0 +1,3 @@ + missing + sha256:f702abcdfcd7ad73619b9285d7e41c3a1d017fb6b8d037cf40bd93bf30c09b2c +? ./greaterThan.dhall diff --git a/dhall/Prelude/Natural/greaterThan.dhall b/dhall/Prelude/Natural/greaterThan.dhall new file mode 100644 index 0000000..9004143 --- /dev/null +++ b/dhall/Prelude/Natural/greaterThan.dhall @@ -0,0 +1,21 @@ +--| `greaterThan` checks if one Natural is strictly greater than another. +let lessThan = + missing + sha256:3381b66749290769badf8855d8a3f4af62e8de52d1364d838a9d1e20c94fa70c + ? ./lessThan.dhall + +let greaterThan + : Natural → Natural → Bool + = λ(x : Natural) → λ(y : Natural) → lessThan y x + +let example0 = assert : greaterThan 5 6 ≡ False + +let example1 = assert : greaterThan 5 5 ≡ False + +let example2 = assert : greaterThan 5 4 ≡ True + +let property0 = λ(n : Natural) → assert : greaterThan 0 n ≡ False + +let property1 = λ(n : Natural) → assert : greaterThan n n ≡ False + +in greaterThan diff --git a/dhall/Prelude/Natural/greaterThanEqual b/dhall/Prelude/Natural/greaterThanEqual new file mode 100644 index 0000000..4eeb30a --- /dev/null +++ b/dhall/Prelude/Natural/greaterThanEqual @@ -0,0 +1,3 @@ + missing + sha256:30ebfab0febd7aa0ccccfdf3dc36ee6d50f0117f35dd4a9b034750b7e885a1a4 +? ./greaterThanEqual.dhall diff --git a/dhall/Prelude/Natural/greaterThanEqual.dhall b/dhall/Prelude/Natural/greaterThanEqual.dhall new file mode 100644 index 0000000..c50f296 --- /dev/null +++ b/dhall/Prelude/Natural/greaterThanEqual.dhall @@ -0,0 +1,23 @@ +{-| +`greaterThanEqual` checks if one Natural is greater than or equal to another. +-} +let lessThanEqual = + missing + sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 + ? ./lessThanEqual.dhall + +let greaterThanEqual + : Natural → Natural → Bool + = λ(x : Natural) → λ(y : Natural) → lessThanEqual y x + +let example0 = assert : greaterThanEqual 5 6 ≡ False + +let example1 = assert : greaterThanEqual 5 5 ≡ True + +let example2 = assert : greaterThanEqual 5 4 ≡ True + +let property0 = λ(n : Natural) → assert : greaterThanEqual n 0 ≡ True + +let property1 = λ(n : Natural) → assert : greaterThanEqual n n ≡ True + +in greaterThanEqual diff --git a/dhall/Prelude/Natural/isZero b/dhall/Prelude/Natural/isZero new file mode 100644 index 0000000..bf048d0 --- /dev/null +++ b/dhall/Prelude/Natural/isZero @@ -0,0 +1,3 @@ + missing + sha256:1be98236800ed2d5cff44f16ca02b34b0c37dfa239d9e0d63d9d2c6eeae3d1d1 +? ./isZero.dhall diff --git a/dhall/Prelude/Natural/isZero.dhall b/dhall/Prelude/Natural/isZero.dhall new file mode 100644 index 0000000..16d5109 --- /dev/null +++ b/dhall/Prelude/Natural/isZero.dhall @@ -0,0 +1,10 @@ +--| Returns `True` if a number is `0` and returns `False` otherwise +let isZero + : Natural → Bool + = Natural/isZero + +let example0 = assert : isZero 2 ≡ False + +let example1 = assert : isZero 0 ≡ True + +in isZero diff --git a/dhall/Prelude/Natural/lessThan b/dhall/Prelude/Natural/lessThan new file mode 100644 index 0000000..1dfa16b --- /dev/null +++ b/dhall/Prelude/Natural/lessThan @@ -0,0 +1,3 @@ + missing + sha256:3381b66749290769badf8855d8a3f4af62e8de52d1364d838a9d1e20c94fa70c +? ./lessThan.dhall diff --git a/dhall/Prelude/Natural/lessThan.dhall b/dhall/Prelude/Natural/lessThan.dhall new file mode 100644 index 0000000..2553c1b --- /dev/null +++ b/dhall/Prelude/Natural/lessThan.dhall @@ -0,0 +1,26 @@ +--| `lessThan` checks if one Natural is strictly less than another. +let greaterThanEqual = + missing + sha256:30ebfab0febd7aa0ccccfdf3dc36ee6d50f0117f35dd4a9b034750b7e885a1a4 + ? ./greaterThanEqual.dhall + +let Bool/not = + missing + sha256:723df402df24377d8a853afed08d9d69a0a6d86e2e5b2bac8960b0d4756c7dc4 + ? ../Bool/not.dhall + +let lessThan + : Natural → Natural → Bool + = λ(x : Natural) → λ(y : Natural) → Bool/not (greaterThanEqual x y) + +let example0 = assert : lessThan 5 6 ≡ True + +let example1 = assert : lessThan 5 5 ≡ False + +let example2 = assert : lessThan 5 4 ≡ False + +let property0 = λ(n : Natural) → assert : lessThan n 0 ≡ False + +let property1 = λ(n : Natural) → assert : lessThan n n ≡ False + +in lessThan diff --git a/dhall/Prelude/Natural/lessThanEqual b/dhall/Prelude/Natural/lessThanEqual new file mode 100644 index 0000000..7160145 --- /dev/null +++ b/dhall/Prelude/Natural/lessThanEqual @@ -0,0 +1,3 @@ + missing + sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 +? ./lessThanEqual.dhall diff --git a/dhall/Prelude/Natural/lessThanEqual.dhall b/dhall/Prelude/Natural/lessThanEqual.dhall new file mode 100644 index 0000000..822d271 --- /dev/null +++ b/dhall/Prelude/Natural/lessThanEqual.dhall @@ -0,0 +1,16 @@ +--| `lessThanEqual` checks if one Natural is less than or equal to another. +let lessThanEqual + : Natural → Natural → Bool + = λ(x : Natural) → λ(y : Natural) → Natural/isZero (Natural/subtract y x) + +let example0 = assert : lessThanEqual 5 6 ≡ True + +let example1 = assert : lessThanEqual 5 5 ≡ True + +let example2 = assert : lessThanEqual 5 4 ≡ False + +let property0 = λ(n : Natural) → assert : lessThanEqual 0 n ≡ True + +let property1 = λ(n : Natural) → assert : lessThanEqual n n ≡ True + +in lessThanEqual diff --git a/dhall/Prelude/Natural/listMax b/dhall/Prelude/Natural/listMax new file mode 100644 index 0000000..482b3e1 --- /dev/null +++ b/dhall/Prelude/Natural/listMax @@ -0,0 +1,3 @@ + missing + sha256:20906ffcc9970f740106d4516cb7868b43d75ff8c9f00ff8a9680ae68c48a472 +? ./listMax.dhall diff --git a/dhall/Prelude/Natural/listMax.dhall b/dhall/Prelude/Natural/listMax.dhall new file mode 100644 index 0000000..f8399b5 --- /dev/null +++ b/dhall/Prelude/Natural/listMax.dhall @@ -0,0 +1,30 @@ +{-| +`listMax` returns the largest element of a `List` or `None Natural` if the +`List` is empty +-} +let max = + missing + sha256:1f3b18da330223ab039fad11693da72c7e68d516f50502c73f41a89a097b62f7 + ? ./max.dhall + +let Optional/map = + missing + sha256:501534192d988218d43261c299cc1d1e0b13d25df388937add784778ab0054fa + ? ../Optional/map.dhall + +let listMax + : List Natural → Optional Natural + = λ(xs : List Natural) → + Optional/map + Natural + Natural + (λ(n : Natural) → List/fold Natural xs Natural max n) + (List/head Natural xs) + +let example0 = assert : listMax [ 1, 2 ] ≡ Some 2 + +let example1 = assert : listMax ([] : List Natural) ≡ None Natural + +let property0 = λ(n : Natural) → assert : listMax [ n ] ≡ Some n + +in listMax diff --git a/dhall/Prelude/Natural/listMin b/dhall/Prelude/Natural/listMin new file mode 100644 index 0000000..780c19c --- /dev/null +++ b/dhall/Prelude/Natural/listMin @@ -0,0 +1,3 @@ + missing + sha256:ee70b0d010bbca6012162e8ae1f6e9d9bd10a152675509b0f23145b98b5d43c6 +? ./listMin.dhall diff --git a/dhall/Prelude/Natural/listMin.dhall b/dhall/Prelude/Natural/listMin.dhall new file mode 100644 index 0000000..d8834ee --- /dev/null +++ b/dhall/Prelude/Natural/listMin.dhall @@ -0,0 +1,34 @@ +{-| +`listMin` returns the smallest element of a `List` or `None Natural` if the +`List` is empty +-} +let min = + missing + sha256:f25f9c462e4dbf0eb15f9ff6ac840c6e9c82255a7f4f2ab408bdab338e028710 + ? ./min.dhall + +let Optional/map = + missing + sha256:501534192d988218d43261c299cc1d1e0b13d25df388937add784778ab0054fa + ? ../Optional/map.dhall + +let listMin + : List Natural → Optional Natural + = λ(xs : List Natural) → + Optional/map + Natural + Natural + ( λ(n : Natural) → + if Natural/isZero n then n else List/fold Natural xs Natural min n + ) + (List/head Natural xs) + +let example0 = assert : listMin [ 0, 1 ] ≡ Some 0 + +let example1 = assert : listMin ([] : List Natural) ≡ None Natural + +let example2 = assert : listMin [ 3, 2, 1 ] ≡ Some 1 + +let property0 = λ(n : Natural) → assert : listMin [ n ] ≡ Some n + +in listMin diff --git a/dhall/Prelude/Natural/max b/dhall/Prelude/Natural/max new file mode 100644 index 0000000..17f25b3 --- /dev/null +++ b/dhall/Prelude/Natural/max @@ -0,0 +1,3 @@ + missing + sha256:1f3b18da330223ab039fad11693da72c7e68d516f50502c73f41a89a097b62f7 +? ./max.dhall diff --git a/dhall/Prelude/Natural/max.dhall b/dhall/Prelude/Natural/max.dhall new file mode 100644 index 0000000..030edd8 --- /dev/null +++ b/dhall/Prelude/Natural/max.dhall @@ -0,0 +1,19 @@ +--| `max a b` returns the larger of `a` or `b` +let lessThanEqual = + missing + sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 + ? ./lessThanEqual.dhall + +let max + : Natural → Natural → Natural + = λ(a : Natural) → λ(b : Natural) → if lessThanEqual a b then b else a + +let example0 = assert : max 1 2 ≡ 2 + +let example1 = assert : max 2 1 ≡ 2 + +let property0 = λ(n : Natural) → assert : max n n ≡ n + +let property1 = λ(n : Natural) → assert : max 0 n ≡ n + +in max diff --git a/dhall/Prelude/Natural/min b/dhall/Prelude/Natural/min new file mode 100644 index 0000000..45305d3 --- /dev/null +++ b/dhall/Prelude/Natural/min @@ -0,0 +1,3 @@ + missing + sha256:f25f9c462e4dbf0eb15f9ff6ac840c6e9c82255a7f4f2ab408bdab338e028710 +? ./min.dhall diff --git a/dhall/Prelude/Natural/min.dhall b/dhall/Prelude/Natural/min.dhall new file mode 100644 index 0000000..daaf0d1 --- /dev/null +++ b/dhall/Prelude/Natural/min.dhall @@ -0,0 +1,17 @@ +--| `min a b` returns the smaller of `a` or `b` +let lessThanEqual = + missing + sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 + ? ./lessThanEqual.dhall + +let min + : Natural → Natural → Natural + = λ(a : Natural) → λ(b : Natural) → if lessThanEqual a b then a else b + +let example0 = assert : min 1 2 ≡ 1 + +let example1 = assert : min 2 1 ≡ 1 + +let property0 = λ(n : Natural) → assert : min n n ≡ n + +in min diff --git a/dhall/Prelude/Natural/odd b/dhall/Prelude/Natural/odd new file mode 100644 index 0000000..09da077 --- /dev/null +++ b/dhall/Prelude/Natural/odd @@ -0,0 +1,3 @@ + missing + sha256:ab3c729262c642ec1cdb72a81e910fcfaf2aea13e3961d0bf1bec83efea5aac5 +? ./odd.dhall diff --git a/dhall/Prelude/Natural/odd.dhall b/dhall/Prelude/Natural/odd.dhall new file mode 100644 index 0000000..801471f --- /dev/null +++ b/dhall/Prelude/Natural/odd.dhall @@ -0,0 +1,10 @@ +--| Returns `True` if a number is odd and returns `False` otherwise +let odd + : Natural → Bool + = Natural/odd + +let example0 = assert : odd 3 ≡ True + +let example1 = assert : odd 0 ≡ False + +in odd diff --git a/dhall/Prelude/Natural/package.dhall b/dhall/Prelude/Natural/package.dhall new file mode 100644 index 0000000..c38602a --- /dev/null +++ b/dhall/Prelude/Natural/package.dhall @@ -0,0 +1,89 @@ +{ build = + missing + sha256:e7e25e6c4f1d8e573606ed1bef725396ac2de5c68f7c5d329ffc5822085b984c + ? ./build.dhall +, enumerate = + missing + sha256:0cf083980a752b21ce0df9fc2222a4c139f50909e2353576e26a191002aa1ce3 + ? ./enumerate.dhall +, even = + missing + sha256:b85b8b56892dfef881e1c0e79eade0b949528f792aac0ea42432b315ede4ee66 + ? ./even.dhall +, fold = + missing + sha256:fd01c931e585a8f5fd049af7b076b862ea164f1813b34800c7616a49e549ee06 + ? ./fold.dhall +, isZero = + missing + sha256:1be98236800ed2d5cff44f16ca02b34b0c37dfa239d9e0d63d9d2c6eeae3d1d1 + ? ./isZero.dhall +, odd = + missing + sha256:ab3c729262c642ec1cdb72a81e910fcfaf2aea13e3961d0bf1bec83efea5aac5 + ? ./odd.dhall +, product = + missing + sha256:e3e6fd76207875b81d39f79fdbc90b5e640444c04fb3d84c2c9326748f0b26e6 + ? ./product.dhall +, sum = + missing + sha256:33f7f4c3aff62e5ecf4848f964363133452d420dcde045784518fb59fa970037 + ? ./sum.dhall +, show = + missing + sha256:684ed560ad86f438efdea229eca122c29e8e14f397ed32ec97148d578ca5aa21 + ? ./show.dhall +, toDouble = + missing + sha256:d5eb52143dcd35b46a6f0cdb2d3cbf31a14b6daeba56e29066f8e344c9fb6e81 + ? ./toDouble.dhall +, toInteger = + missing + sha256:160d2d278619f3da34a1f4f02e739a447e4f2aa5a2978c45b710515b41491e1f + ? ./toInteger.dhall +, lessThan = + missing + sha256:3381b66749290769badf8855d8a3f4af62e8de52d1364d838a9d1e20c94fa70c + ? ./lessThan.dhall +, lessThanEqual = + missing + sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 + ? ./lessThanEqual.dhall +, equal = + missing + sha256:7f108edfa35ddc7cebafb24dc073478e93a802e13b5bc3fd22f4768c9b066e60 + ? ./equal.dhall +, greaterThanEqual = + missing + sha256:30ebfab0febd7aa0ccccfdf3dc36ee6d50f0117f35dd4a9b034750b7e885a1a4 + ? ./greaterThanEqual.dhall +, greaterThan = + missing + sha256:f702abcdfcd7ad73619b9285d7e41c3a1d017fb6b8d037cf40bd93bf30c09b2c + ? ./greaterThan.dhall +, min = + missing + sha256:f25f9c462e4dbf0eb15f9ff6ac840c6e9c82255a7f4f2ab408bdab338e028710 + ? ./min.dhall +, max = + missing + sha256:1f3b18da330223ab039fad11693da72c7e68d516f50502c73f41a89a097b62f7 + ? ./max.dhall +, listMin = + missing + sha256:ee70b0d010bbca6012162e8ae1f6e9d9bd10a152675509b0f23145b98b5d43c6 + ? ./listMin.dhall +, listMax = + missing + sha256:20906ffcc9970f740106d4516cb7868b43d75ff8c9f00ff8a9680ae68c48a472 + ? ./listMax.dhall +, sort = + missing + sha256:36ce8b3e5538454763987ca904d8d7c5ba34c2147434a19eddd51f684432b260 + ? ./sort.dhall +, subtract = + missing + sha256:b9277ac637d09142a3a3ac79137ef5955c42f8b33b6746d59db2c9d75ccdd745 + ? ./subtract.dhall +} diff --git a/dhall/Prelude/Natural/product b/dhall/Prelude/Natural/product new file mode 100644 index 0000000..5b637d0 --- /dev/null +++ b/dhall/Prelude/Natural/product @@ -0,0 +1,3 @@ + missing + sha256:e3e6fd76207875b81d39f79fdbc90b5e640444c04fb3d84c2c9326748f0b26e6 +? ./product.dhall diff --git a/dhall/Prelude/Natural/product.dhall b/dhall/Prelude/Natural/product.dhall new file mode 100644 index 0000000..803f67c --- /dev/null +++ b/dhall/Prelude/Natural/product.dhall @@ -0,0 +1,11 @@ +--| Multiply all the numbers in a `List` +let product + : List Natural → Natural + = λ(xs : List Natural) → + List/fold Natural xs Natural (λ(l : Natural) → λ(r : Natural) → l * r) 1 + +let example0 = assert : product [ 2, 3, 5 ] ≡ 30 + +let example1 = assert : product ([] : List Natural) ≡ 1 + +in product diff --git a/dhall/Prelude/Natural/show b/dhall/Prelude/Natural/show new file mode 100644 index 0000000..e0427b6 --- /dev/null +++ b/dhall/Prelude/Natural/show @@ -0,0 +1,3 @@ + missing + sha256:684ed560ad86f438efdea229eca122c29e8e14f397ed32ec97148d578ca5aa21 +? ./show.dhall diff --git a/dhall/Prelude/Natural/show.dhall b/dhall/Prelude/Natural/show.dhall new file mode 100644 index 0000000..8547c15 --- /dev/null +++ b/dhall/Prelude/Natural/show.dhall @@ -0,0 +1,13 @@ +{-| +Render a `Natural` number as `Text` using the same representation as Dhall +source code (i.e. a decimal number) +-} +let show + : Natural → Text + = Natural/show + +let example0 = assert : show 3 ≡ "3" + +let example1 = assert : show 0 ≡ "0" + +in show diff --git a/dhall/Prelude/Natural/sort b/dhall/Prelude/Natural/sort new file mode 100644 index 0000000..ffb6ff9 --- /dev/null +++ b/dhall/Prelude/Natural/sort @@ -0,0 +1,3 @@ + missing + sha256:36ce8b3e5538454763987ca904d8d7c5ba34c2147434a19eddd51f684432b260 +? ./sort.dhall diff --git a/dhall/Prelude/Natural/sort.dhall b/dhall/Prelude/Natural/sort.dhall new file mode 100644 index 0000000..d0d8e15 --- /dev/null +++ b/dhall/Prelude/Natural/sort.dhall @@ -0,0 +1,61 @@ +--| `sort` sorts a `List` of `Natural`s in ascending order +let greaterThanEqual = + missing + sha256:30ebfab0febd7aa0ccccfdf3dc36ee6d50f0117f35dd4a9b034750b7e885a1a4 + ? ./greaterThanEqual.dhall + +let listMin = + missing + sha256:ee70b0d010bbca6012162e8ae1f6e9d9bd10a152675509b0f23145b98b5d43c6 + ? ./listMin.dhall + +let List/partition = + missing + sha256:38147ac6d750a6492736dd90cc967bf09aa405c499de943c64fab7b86ae02f03 + ? ../List/partition.dhall + +let Accumulator = { sorted : List Natural, rest : List Natural } + +let partitionMinima = + λ(xs : List Natural) → + merge + { Some = + λ(m : Natural) → List/partition Natural (greaterThanEqual m) xs + , None = { true = [] : List Natural, false = [] : List Natural } + } + (listMin xs) + +let test0 = + assert + : partitionMinima [ 2, 1, 1, 3 ] ≡ { true = [ 1, 1 ], false = [ 2, 3 ] } + +let step = + λ(x : Accumulator) → + let p = partitionMinima x.rest + + in { sorted = x.sorted # p.true, rest = p.false } + +let test1 = + assert + : step { sorted = [ 1, 1 ], rest = [ 2, 3 ] } + ≡ { sorted = [ 1, 1, 2 ], rest = [ 3 ] } + +let sort + : List Natural → List Natural + = λ(xs : List Natural) → + let x = + Natural/fold + (List/length Natural xs) + Accumulator + step + { sorted = [] : List Natural, rest = xs } + + in x.sorted + +let example0 = assert : sort ([] : List Natural) ≡ ([] : List Natural) + +let example1 = assert : sort [ 1 ] ≡ [ 1 ] + +let example2 = assert : sort [ 3, 2, 1, 3, 2, 1 ] ≡ [ 1, 1, 2, 2, 3, 3 ] + +in sort diff --git a/dhall/Prelude/Natural/subtract b/dhall/Prelude/Natural/subtract new file mode 100644 index 0000000..d427d40 --- /dev/null +++ b/dhall/Prelude/Natural/subtract @@ -0,0 +1,3 @@ + missing + sha256:b9277ac637d09142a3a3ac79137ef5955c42f8b33b6746d59db2c9d75ccdd745 +? ./subtract.dhall diff --git a/dhall/Prelude/Natural/subtract.dhall b/dhall/Prelude/Natural/subtract.dhall new file mode 100644 index 0000000..47352b5 --- /dev/null +++ b/dhall/Prelude/Natural/subtract.dhall @@ -0,0 +1,18 @@ +--| `subtract m n` computes `n - m`, truncating to `0` if `m > n` +let subtract + : Natural → Natural → Natural + = Natural/subtract + +let example0 = assert : subtract 1 2 ≡ 1 + +let example1 = assert : subtract 1 1 ≡ 0 + +let example2 = assert : subtract 2 1 ≡ 0 + +let property0 = λ(n : Natural) → assert : subtract 0 n ≡ n + +let property1 = λ(n : Natural) → assert : subtract n 0 ≡ 0 + +let property2 = λ(n : Natural) → assert : subtract n n ≡ 0 + +in subtract diff --git a/dhall/Prelude/Natural/sum b/dhall/Prelude/Natural/sum new file mode 100644 index 0000000..09ecc55 --- /dev/null +++ b/dhall/Prelude/Natural/sum @@ -0,0 +1,3 @@ + missing + sha256:33f7f4c3aff62e5ecf4848f964363133452d420dcde045784518fb59fa970037 +? ./sum.dhall diff --git a/dhall/Prelude/Natural/sum.dhall b/dhall/Prelude/Natural/sum.dhall new file mode 100644 index 0000000..40b6920 --- /dev/null +++ b/dhall/Prelude/Natural/sum.dhall @@ -0,0 +1,11 @@ +--| Add all the numbers in a `List` +let sum + : List Natural → Natural + = λ(xs : List Natural) → + List/fold Natural xs Natural (λ(l : Natural) → λ(r : Natural) → l + r) 0 + +let example = assert : sum [ 2, 3, 5 ] ≡ 10 + +let example = assert : sum ([] : List Natural) ≡ 0 + +in sum diff --git a/dhall/Prelude/Natural/toDouble b/dhall/Prelude/Natural/toDouble new file mode 100644 index 0000000..c3d8533 --- /dev/null +++ b/dhall/Prelude/Natural/toDouble @@ -0,0 +1,3 @@ + missing + sha256:d5eb52143dcd35b46a6f0cdb2d3cbf31a14b6daeba56e29066f8e344c9fb6e81 +? ./toDouble.dhall diff --git a/dhall/Prelude/Natural/toDouble.dhall b/dhall/Prelude/Natural/toDouble.dhall new file mode 100644 index 0000000..ecd6cd0 --- /dev/null +++ b/dhall/Prelude/Natural/toDouble.dhall @@ -0,0 +1,10 @@ +--| Convert a `Natural` number to the corresponding `Double` +let toDouble + : Natural → Double + = λ(n : Natural) → Integer/toDouble (Natural/toInteger n) + +let example0 = assert : toDouble 3 ≡ 3.0 + +let example1 = assert : toDouble 0 ≡ 0.0 + +in toDouble diff --git a/dhall/Prelude/Natural/toInteger b/dhall/Prelude/Natural/toInteger new file mode 100644 index 0000000..2ffd1ae --- /dev/null +++ b/dhall/Prelude/Natural/toInteger @@ -0,0 +1,3 @@ + missing + sha256:160d2d278619f3da34a1f4f02e739a447e4f2aa5a2978c45b710515b41491e1f +? ./toInteger.dhall diff --git a/dhall/Prelude/Natural/toInteger.dhall b/dhall/Prelude/Natural/toInteger.dhall new file mode 100644 index 0000000..05b4a2d --- /dev/null +++ b/dhall/Prelude/Natural/toInteger.dhall @@ -0,0 +1,10 @@ +--| Convert a `Natural` number to the corresponding `Integer` +let toInteger + : Natural → Integer + = Natural/toInteger + +let example0 = assert : toInteger 3 ≡ +3 + +let example1 = assert : toInteger 0 ≡ +0 + +in toInteger diff --git a/dhall/Prelude/NonEmpty/Type.dhall b/dhall/Prelude/NonEmpty/Type.dhall new file mode 100644 index 0000000..300bb67 --- /dev/null +++ b/dhall/Prelude/NonEmpty/Type.dhall @@ -0,0 +1,9 @@ +{-| +A `NonEmpty` list has at least one element and supports many of the same +operations as `List`s +-} +let NonEmpty + : Type → Type + = λ(a : Type) → { head : a, tail : List a } + +in NonEmpty diff --git a/dhall/Prelude/NonEmpty/all.dhall b/dhall/Prelude/NonEmpty/all.dhall new file mode 100644 index 0000000..46f9cd4 --- /dev/null +++ b/dhall/Prelude/NonEmpty/all.dhall @@ -0,0 +1,34 @@ +{-| +Returns `True` if the supplied function returns `True` for all elements in the +`NonEmpty` list +-} +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let NonEmpty/toList = + missing + sha256:0977fe14b77232a4451dcf409c43df4589c4b3cdde7b613aab8df183be1b53f5 + ? ./toList.dhall + +let all + : ∀(a : Type) → (a → Bool) → NonEmpty a → Bool + = λ(a : Type) → + λ(f : a → Bool) → + λ(xs : NonEmpty a) → + List/fold + a + (NonEmpty/toList a xs) + Bool + (λ(x : a) → λ(r : Bool) → f x && r) + True + +let example0 = + assert : all Natural Natural/even { head = 2, tail = [ 3, 5 ] } ≡ False + +let example1 = + assert + : all Natural Natural/even { head = 2, tail = [] : List Natural } ≡ True + +in all diff --git a/dhall/Prelude/NonEmpty/any.dhall b/dhall/Prelude/NonEmpty/any.dhall new file mode 100644 index 0000000..1d453be --- /dev/null +++ b/dhall/Prelude/NonEmpty/any.dhall @@ -0,0 +1,34 @@ +{-| +Returns `True` if the supplied function returns `True` for any element in the +`NonEmpty` list +-} +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let NonEmpty/toList = + missing + sha256:0977fe14b77232a4451dcf409c43df4589c4b3cdde7b613aab8df183be1b53f5 + ? ./toList.dhall + +let any + : ∀(a : Type) → (a → Bool) → NonEmpty a → Bool + = λ(a : Type) → + λ(f : a → Bool) → + λ(xs : NonEmpty a) → + List/fold + a + (NonEmpty/toList a xs) + Bool + (λ(x : a) → λ(r : Bool) → f x || r) + False + +let example0 = + assert : any Natural Natural/even { head = 2, tail = [ 3, 5 ] } ≡ True + +let example1 = + assert + : any Natural Natural/even { head = 3, tail = [] : List Natural } ≡ False + +in any diff --git a/dhall/Prelude/NonEmpty/concat.dhall b/dhall/Prelude/NonEmpty/concat.dhall new file mode 100644 index 0000000..d866ebf --- /dev/null +++ b/dhall/Prelude/NonEmpty/concat.dhall @@ -0,0 +1,61 @@ +{-| +Concatenate a `NonEmpty` list of `NonEmpty` lists into a single `NonEmpty` +list +-} +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let NonEmpty/toList = + missing + sha256:0977fe14b77232a4451dcf409c43df4589c4b3cdde7b613aab8df183be1b53f5 + ? ./toList.dhall + +let List/concatMap = + missing + sha256:3b2167061d11fda1e4f6de0522cbe83e0d5ac4ef5ddf6bb0b2064470c5d3fb64 + ? ../List/concatMap.dhall + +let concat + : ∀(a : Type) → NonEmpty (NonEmpty a) → NonEmpty a + = λ(a : Type) → + λ(xss : NonEmpty (NonEmpty a)) → + { head = xss.head.head + , tail = + xss.head.tail + # List/concatMap (NonEmpty a) a (NonEmpty/toList a) xss.tail + } + +let example0 = + assert + : concat + Natural + { head = { head = 0, tail = [ 1, 2 ] } + , tail = + [ { head = 3, tail = [ 4 ] }, { head = 5, tail = [ 6, 7, 8 ] } ] + } + ≡ { head = 0, tail = [ 1, 2, 3, 4, 5, 6, 7, 8 ] } + +let example1 = + assert + : concat + Natural + { head = { head = 0, tail = [] : List Natural } + , tail = + [ { head = 1, tail = [] : List Natural } + , { head = 2, tail = [] : List Natural } + ] + } + ≡ { head = 0, tail = [ 1, 2 ] : List Natural } + +let example2 = + assert + : concat + Natural + { head = { head = 0, tail = [] : List Natural } + , tail = [] : List (NonEmpty Natural) + } + ≡ { head = 0, tail = [] : List Natural } + +in concat diff --git a/dhall/Prelude/NonEmpty/concatMap.dhall b/dhall/Prelude/NonEmpty/concatMap.dhall new file mode 100644 index 0000000..ab28461 --- /dev/null +++ b/dhall/Prelude/NonEmpty/concatMap.dhall @@ -0,0 +1,56 @@ +{-| +Transform a `NonEmpty` list by applying a function to each element and +flattening the results +-} +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let NonEmpty/toList = + missing + sha256:0977fe14b77232a4451dcf409c43df4589c4b3cdde7b613aab8df183be1b53f5 + ? ./toList.dhall + +let List/concatMap = + missing + sha256:3b2167061d11fda1e4f6de0522cbe83e0d5ac4ef5ddf6bb0b2064470c5d3fb64 + ? ../List/concatMap.dhall + +let concatMap + : ∀(a : Type) → ∀(b : Type) → (a → NonEmpty b) → NonEmpty a → NonEmpty b + = λ(a : Type) → + λ(b : Type) → + λ(f : a → NonEmpty b) → + λ(xs : NonEmpty a) → + let ys = f xs.head + + in { head = ys.head + , tail = + ys.tail + # List/concatMap + a + b + (λ(x : a) → NonEmpty/toList b (f x)) + xs.tail + } + +let example0 = + assert + : concatMap + Natural + Natural + (λ(n : Natural) → { head = n, tail = [ n ] }) + { head = 2, tail = [ 3, 5 ] } + ≡ { head = 2, tail = [ 2, 3, 3, 5, 5 ] } + +let example1 = + assert + : concatMap + Natural + Natural + (λ(n : Natural) → { head = n, tail = [ n ] }) + { head = 2, tail = [] : List Natural } + ≡ { head = 2, tail = [ 2 ] } + +in concatMap diff --git a/dhall/Prelude/NonEmpty/head.dhall b/dhall/Prelude/NonEmpty/head.dhall new file mode 100644 index 0000000..7927a29 --- /dev/null +++ b/dhall/Prelude/NonEmpty/head.dhall @@ -0,0 +1,13 @@ +--| Retrieve the first element of the `NonEmpty` list +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let head + : ∀(a : Type) → NonEmpty a → a + = λ(a : Type) → λ(xs : NonEmpty a) → xs.head + +let example = assert : head Natural { head = 0, tail = [ 1, 2 ] } ≡ 0 + +in head diff --git a/dhall/Prelude/NonEmpty/index.dhall b/dhall/Prelude/NonEmpty/index.dhall new file mode 100644 index 0000000..c85135a --- /dev/null +++ b/dhall/Prelude/NonEmpty/index.dhall @@ -0,0 +1,33 @@ +--| Retrieve an element from a `NonEmpty` list using its 0-based index +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let List/index = + missing + sha256:e657b55ecae4d899465c3032cb1a64c6aa6dc2aa3034204f3c15ce5c96c03e63 + ? ../List/index.dhall + +let index + : Natural → ∀(a : Type) → NonEmpty a → Optional a + = λ(n : Natural) → + λ(a : Type) → + λ(xs : NonEmpty a) → + if Natural/isZero n + then Some xs.head + else List/index (Natural/subtract 1 n) a xs.tail + +let property = + λ(n : Natural) → + λ(a : Type) → + λ(xs : NonEmpty a) → + assert : index 0 a xs ≡ Some xs.head + +let example0 = assert : index 1 Natural { head = 2, tail = [ 3, 5 ] } ≡ Some 3 + +let example1 = + assert + : index 1 Natural { head = 2, tail = [] : List Natural } ≡ None Natural + +in index diff --git a/dhall/Prelude/NonEmpty/indexed.dhall b/dhall/Prelude/NonEmpty/indexed.dhall new file mode 100644 index 0000000..ef6f7d0 --- /dev/null +++ b/dhall/Prelude/NonEmpty/indexed.dhall @@ -0,0 +1,41 @@ +--| Tag each element of the `NonEmpty` list with its index +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map.dhall + +let indexed + : ∀(a : Type) → NonEmpty a → NonEmpty { index : Natural, value : a } + = λ(a : Type) → + λ(xs : NonEmpty a) → + { head = { index = 0, value = xs.head } + , tail = + List/map + { index : Natural, value : a } + { index : Natural, value : a } + ( λ(ix : { index : Natural, value : a }) → + { index = ix.index + 1, value = ix.value } + ) + (List/indexed a xs.tail) + } + +let example0 = + assert + : indexed Bool { head = True, tail = [ False, True ] } + ≡ { head = { index = 0, value = True } + , tail = [ { index = 1, value = False }, { index = 2, value = True } ] + } + +let example1 = + assert + : indexed Bool { head = True, tail = [] : List Bool } + ≡ { head = { index = 0, value = True } + , tail = [] : List { index : Natural, value : Bool } + } + +in indexed diff --git a/dhall/Prelude/NonEmpty/last.dhall b/dhall/Prelude/NonEmpty/last.dhall new file mode 100644 index 0000000..9b5e97a --- /dev/null +++ b/dhall/Prelude/NonEmpty/last.dhall @@ -0,0 +1,17 @@ +--| Retrieve the last element of the `NonEmpty` list +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let last + : ∀(a : Type) → NonEmpty a → a + = λ(a : Type) → + λ(xs : NonEmpty a) → + merge { Some = λ(x : a) → x, None = xs.head } (List/last a xs.tail) + +let example0 = assert : last Natural { head = 0, tail = [ 1, 2 ] } ≡ 2 + +let example1 = assert : last Natural { head = 0, tail = [] : List Natural } ≡ 0 + +in last diff --git a/dhall/Prelude/NonEmpty/length.dhall b/dhall/Prelude/NonEmpty/length.dhall new file mode 100644 index 0000000..def01e2 --- /dev/null +++ b/dhall/Prelude/NonEmpty/length.dhall @@ -0,0 +1,16 @@ +--| Returns the number of elements in a `NonEmpty` list +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let length + : ∀(a : Type) → NonEmpty a → Natural + = λ(a : Type) → λ(xs : NonEmpty a) → List/length a xs.tail + 1 + +let example0 = assert : length Natural { head = 0, tail = [ 1, 2 ] } ≡ 3 + +let example1 = + assert : length Natural { head = 0, tail = [] : List Natural } ≡ 1 + +in length diff --git a/dhall/Prelude/NonEmpty/make.dhall b/dhall/Prelude/NonEmpty/make.dhall new file mode 100644 index 0000000..9b1d776 --- /dev/null +++ b/dhall/Prelude/NonEmpty/make.dhall @@ -0,0 +1,18 @@ +{-| +Create a `NonEmpty` list using a function instead of a record + +This might come in handy if you want to decouple the `NonEmpty` list +construction from the specific names of the fields. +-} +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let make + : ∀(a : Type) → ∀(head : a) → ∀(tail : List a) → NonEmpty a + = λ(a : Type) → λ(head : a) → λ(tail : List a) → { head, tail } + +let example = assert : make Natural 1 [ 2, 3 ] ≡ { head = 1, tail = [ 2, 3 ] } + +in make diff --git a/dhall/Prelude/NonEmpty/map.dhall b/dhall/Prelude/NonEmpty/map.dhall new file mode 100644 index 0000000..7e25b7a --- /dev/null +++ b/dhall/Prelude/NonEmpty/map.dhall @@ -0,0 +1,30 @@ +--| Transform a `NonEmpty` list by applying a function to each element +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map.dhall + +let map + : ∀(a : Type) → ∀(b : Type) → (a → b) → NonEmpty a → NonEmpty b + = λ(a : Type) → + λ(b : Type) → + λ(f : a → b) → + λ(xs : NonEmpty a) → + { head = f xs.head, tail = List/map a b f xs.tail } + +let example0 = + assert + : map Natural Bool Natural/even { head = 2, tail = [ 3, 5 ] } + ≡ { head = True, tail = [ False, False ] } + +let example1 = + assert + : map Natural Bool Natural/even { head = 2, tail = [] : List Natural } + ≡ { head = True, tail = [] : List Bool } + +in map diff --git a/dhall/Prelude/NonEmpty/package.dhall b/dhall/Prelude/NonEmpty/package.dhall new file mode 100644 index 0000000..fbe4b33 --- /dev/null +++ b/dhall/Prelude/NonEmpty/package.dhall @@ -0,0 +1,73 @@ +{ Type = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall +, all = + missing + sha256:f2f9389d94f4deb5b918b2e50c1093b57e00b37ddd3ab2b43959993b1cb519b6 + ? ./all.dhall +, any = + missing + sha256:7662b665840e41b12a28190eec3aaab9201fcb90c00a8ec3666d549e1020992f + ? ./any.dhall +, concat = + missing + sha256:6d55181938c06c6b806877028f6a241912e9c0935d9a10dd958775bf21e0f64d + ? ./concat.dhall +, concatMap = + missing + sha256:fc33fa9449dc8f74dd8c8be379b7b7c4b0433e2b65650370d81d9a7111a590e2 + ? ./concatMap.dhall +, head = + missing + sha256:6b9551c97b89fe666d2e03392a4af5e87abfdbdb0aa0e29fc4b3aa1b318474e7 + ? ./head.dhall +, index = + missing + sha256:0ba2fcc9227fab10676cd61b47a18d779818a19c16727c7cc4b4c78e114fd663 + ? ./index.dhall +, indexed = + missing + sha256:9dae2c1fecd142df837e98769b5bbdd0bfe25c35a93af1064b4e62f9c780ae6b + ? ./indexed.dhall +, last = + missing + sha256:f83115492b6e408d0b662a68440620f7f3df07b56e7ed66dab77a6e65b121250 + ? ./last.dhall +, length = + missing + sha256:eef3b857a164487cfdb960e3298c4731970b7a430011289cba35a9ad722ac989 + ? ./length.dhall +, make = + missing + sha256:549de393673c4773c80a50ea578ea50d7f2c4c2eda31956e73fabc4e486f3b1e + ? ./make.dhall +, map = + missing + sha256:93d53afe874bb2eed946c21ca5ada3c9716b7d00e6d8edfaba6484cd9c5a00bd + ? ./map.dhall +, reverse = + missing + sha256:a6d810cdd3badffd4e7ca82091609a855cffac900c82d7ff3724463fbc2d5ff2 + ? ./reverse.dhall +, shifted = + missing + sha256:36156973d6916aed10cfd8c59be7c019516bf0a2c47b499a17a8ef0611e1c189 + ? ./shifted.dhall +, singleton = + missing + sha256:c9197aabe97695f7ca66f7419bf172d806b2c915594a8fc0d2ff6495db496ff2 + ? ./singleton.dhall +, toList = + missing + sha256:0977fe14b77232a4451dcf409c43df4589c4b3cdde7b613aab8df183be1b53f5 + ? ./toList.dhall +, unzip = + missing + sha256:d0b925bea32a29aad5cb48a84e8ef8cff750308afe1dd20b24eca19e4e999abc + ? ./unzip.dhall +, zip = + missing + sha256:073f8b4808b6d1db84964f772f6291e6ea193602163438db43fa282c560c01e4 + ? ./zip.dhall +} diff --git a/dhall/Prelude/NonEmpty/reverse.dhall b/dhall/Prelude/NonEmpty/reverse.dhall new file mode 100644 index 0000000..7940f38 --- /dev/null +++ b/dhall/Prelude/NonEmpty/reverse.dhall @@ -0,0 +1,35 @@ +--| Reverse a `NonEmpty` list +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let List/drop = + missing + sha256:af983ba3ead494dd72beed05c0f3a17c36a4244adedf7ced502c6512196ed0cf + ? ../List/drop.dhall + +let reverse + : ∀(a : Type) → NonEmpty a → NonEmpty a + = λ(a : Type) → + λ(xs : NonEmpty a) → + let ys = List/reverse a xs.tail + + in merge + { Some = + λ(y : a) → { head = y, tail = List/drop 1 a ys # [ xs.head ] } + , None = { head = xs.head, tail = [] : List a } + } + (List/head a ys) + +let example = + assert + : reverse Natural { head = 0, tail = [ 1, 2 ] } + ≡ { head = 2, tail = [ 1, 0 ] } + +let example1 = + assert + : reverse Natural { head = 0, tail = [] : List Natural } + ≡ { head = 0, tail = [] : List Natural } + +in reverse diff --git a/dhall/Prelude/NonEmpty/shifted.dhall b/dhall/Prelude/NonEmpty/shifted.dhall new file mode 100644 index 0000000..79c65f7 --- /dev/null +++ b/dhall/Prelude/NonEmpty/shifted.dhall @@ -0,0 +1,101 @@ +{-| +Combine a `NonEmpty` list of `NonEmpty` lists, offsetting the `index` of each +element by the number of elements in preceding lists +-} +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let NonEmpty/toList = + missing + sha256:0977fe14b77232a4451dcf409c43df4589c4b3cdde7b613aab8df183be1b53f5 + ? ./toList.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map.dhall + +let List/shifted = + missing + sha256:54fb22c7e952ebce1cfc0fcdd33ce4cfa817bff9d6564af268dea6685f8b5dfe + ? ../List/shifted.dhall + +let shifted + : ∀(a : Type) → + NonEmpty (NonEmpty { index : Natural, value : a }) → + NonEmpty { index : Natural, value : a } + = λ(a : Type) → + λ(kvss : NonEmpty (NonEmpty { index : Natural, value : a })) → + { head = kvss.head.head + , tail = + List/shifted + a + ( [ kvss.head.tail ] + # List/map + (NonEmpty { index : Natural, value : a }) + (List { index : Natural, value : a }) + ( λ(kvs : NonEmpty { index : Natural, value : a }) → + List/map + { index : Natural, value : a } + { index : Natural, value : a } + ( λ(kv : { index : Natural, value : a }) → + { index = kv.index + 1, value = kv.value } + ) + (NonEmpty/toList { index : Natural, value : a } kvs) + ) + kvss.tail + ) + } + +let example0 = + assert + : shifted + Bool + { head = + { head = { index = 0, value = True } + , tail = + [ { index = 1, value = True }, { index = 2, value = True } ] + } + , tail = + [ { head = { index = 0, value = False } + , tail = [ { index = 1, value = False } ] + } + , { head = { index = 0, value = True } + , tail = + [ { index = 1, value = True } + , { index = 2, value = True } + , { index = 3, value = True } + ] + } + ] + } + ≡ { head = { index = 0, value = True } + , tail = + [ { index = 1, value = True } + , { index = 2, value = True } + , { index = 3, value = False } + , { index = 4, value = False } + , { index = 5, value = True } + , { index = 6, value = True } + , { index = 7, value = True } + , { index = 8, value = True } + ] + } + +let example1 = + assert + : shifted + Bool + { head = + { head = { index = 0, value = True } + , tail = [] : List { index : Natural, value : Bool } + } + , tail = [] : List (NonEmpty { index : Natural, value : Bool }) + } + ≡ { head = { index = 0, value = True } + , tail = [] : List { index : Natural, value : Bool } + } + +in shifted diff --git a/dhall/Prelude/NonEmpty/singleton.dhall b/dhall/Prelude/NonEmpty/singleton.dhall new file mode 100644 index 0000000..ad6418a --- /dev/null +++ b/dhall/Prelude/NonEmpty/singleton.dhall @@ -0,0 +1,14 @@ +--| Create a `NonEmpty` list with just one element +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let singleton + : ∀(a : Type) → a → NonEmpty a + = λ(a : Type) → λ(x : a) → { head = x, tail = [] : List a } + +let example = + assert : singleton Natural 2 ≡ { head = 2, tail = [] : List Natural } + +in singleton diff --git a/dhall/Prelude/NonEmpty/toList.dhall b/dhall/Prelude/NonEmpty/toList.dhall new file mode 100644 index 0000000..c607dab --- /dev/null +++ b/dhall/Prelude/NonEmpty/toList.dhall @@ -0,0 +1,17 @@ +--| Convert a `NonEmpty` list into the equivalent `List` +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let toList + : ∀(a : Type) → NonEmpty a → List a + = λ(a : Type) → λ(xs : NonEmpty a) → [ xs.head ] # xs.tail + +let example0 = + assert : toList Natural { head = 2, tail = [ 3, 5 ] } ≡ [ 2, 3, 5 ] + +let example1 = + assert : toList Natural { head = 2, tail = [] : List Natural } ≡ [ 2 ] + +in toList diff --git a/dhall/Prelude/NonEmpty/unzip.dhall b/dhall/Prelude/NonEmpty/unzip.dhall new file mode 100644 index 0000000..d82e5e3 --- /dev/null +++ b/dhall/Prelude/NonEmpty/unzip.dhall @@ -0,0 +1,58 @@ +--| Unzip a `NonEmpty` list into two separate `NonEmpty` lists +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let NonEmpty/map = + missing + sha256:93d53afe874bb2eed946c21ca5ada3c9716b7d00e6d8edfaba6484cd9c5a00bd + ? ./map.dhall + +let unzip + : ∀(a : Type) → + ∀(b : Type) → + NonEmpty { _1 : a, _2 : b } → + { _1 : NonEmpty a, _2 : NonEmpty b } + = λ(a : Type) → + λ(b : Type) → + λ(xs : NonEmpty { _1 : a, _2 : b }) → + { _1 = + NonEmpty/map + { _1 : a, _2 : b } + a + (λ(x : { _1 : a, _2 : b }) → x._1) + xs + , _2 = + NonEmpty/map + { _1 : a, _2 : b } + b + (λ(x : { _1 : a, _2 : b }) → x._2) + xs + } + +let example0 = + assert + : unzip + Text + Bool + { head = { _1 = "ABC", _2 = True } + , tail = [ { _1 = "DEF", _2 = False }, { _1 = "GHI", _2 = True } ] + } + ≡ { _1 = { head = "ABC", tail = [ "DEF", "GHI" ] } + , _2 = { head = True, tail = [ False, True ] } + } + +let example1 = + assert + : unzip + Text + Bool + { head = { _1 = "ABC", _2 = True } + , tail = [] : List { _1 : Text, _2 : Bool } + } + ≡ { _1 = { head = "ABC", tail = [] : List Text } + , _2 = { head = True, tail = [] : List Bool } + } + +in unzip diff --git a/dhall/Prelude/NonEmpty/zip.dhall b/dhall/Prelude/NonEmpty/zip.dhall new file mode 100644 index 0000000..73e2e03 --- /dev/null +++ b/dhall/Prelude/NonEmpty/zip.dhall @@ -0,0 +1,63 @@ +{-| +Zip two `NonEmpty` lists into a single `NonEmpty` + +The resulting `NonEmpty` will have the length of the shortest of its arguments. +-} +let NonEmpty = + missing + sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f + ? ./Type.dhall + +let List/zip = + missing + sha256:85ed955eabf3998767f4ad2a28e57d40cd4c68a95519d79e9b622f1d26d979da + ? ../List/zip.dhall + +let zip + : ∀(a : Type) → + NonEmpty a → + ∀(b : Type) → + NonEmpty b → + NonEmpty { _1 : a, _2 : b } + = λ(a : Type) → + λ(xs : NonEmpty a) → + λ(b : Type) → + λ(ys : NonEmpty b) → + { head = { _1 = xs.head, _2 = ys.head } + , tail = List/zip a xs.tail b ys.tail + } + +let example0 = + assert + : zip + Text + { head = "ABC", tail = [ "DEF", "GHI" ] } + Natural + { head = 1, tail = [ 2, 3 ] } + ≡ { head = { _1 = "ABC", _2 = 1 } + , tail = [ { _1 = "DEF", _2 = 2 }, { _1 = "GHI", _2 = 3 } ] + } + +let example1 = + assert + : zip + Text + { head = "ABC", tail = [ "DEF" ] } + Bool + { head = True, tail = [] : List Bool } + ≡ { head = { _1 = "ABC", _2 = True } + , tail = [] : List { _1 : Text, _2 : Bool } + } + +let example2 = + assert + : zip + Text + { head = "ABC", tail = [] : List Text } + Natural + { head = 1, tail = [ 2 ] } + ≡ { head = { _1 = "ABC", _2 = 1 } + , tail = [] : List { _1 : Text, _2 : Natural } + } + +in zip diff --git a/dhall/Prelude/Operator/package.dhall b/dhall/Prelude/Operator/package.dhall new file mode 100644 index 0000000..02ba44e --- /dev/null +++ b/dhall/Prelude/Operator/package.dhall @@ -0,0 +1,85 @@ +{- +Note: This package does not use one file per function because the operator +names contain symbols such as `*` that may cause problems. +-} +let {- + `+` m n + + computes `m + n` + -} `+` + : Natural → Natural → Natural + = λ(m : Natural) → λ(n : Natural) → m + n + +let example1 = assert : `+` 2 1 ≡ 3 + +let {- + `*` m n + + computes `m * n` + -} `*` + : Natural → Natural → Natural + = λ(m : Natural) → λ(n : Natural) → m * n + +let example2 = assert : `*` 21 2 ≡ 42 + +let {- + `++` m n + + computes `m ++ n` + -} `++` + : Text → Text → Text + = λ(m : Text) → λ(n : Text) → m ++ n + +let example3 = assert : `++` "Hello" "Dhall" ≡ "HelloDhall" + +let {- + `#` Type m n + + computes `m # n` + -} `#` + : ∀(type : Type) → List type → List type → List type + = λ(type : Type) → λ(m : List type) → λ(n : List type) → m # n + +let example4 = assert : `#` Natural [ 1, 2 ] [ 3 ] ≡ [ 1, 2, 3 ] + +let {- + `==` m n + + computes `m == n` + -} `==` + : Bool → Bool → Bool + = λ(m : Bool) → λ(n : Bool) → m == n + +let example5 = assert : `==` True False ≡ False + +let {- + `!=` m n + + computes `m != n` + -} `!=` + : Bool → Bool → Bool + = λ(m : Bool) → λ(n : Bool) → m != n + +let example6 = assert : `!=` True False ≡ True + +let {- + `&&` m n + + computes `m && n` + -} `&&` + : Bool → Bool → Bool + = λ(m : Bool) → λ(n : Bool) → m && n + +let example7 = assert : `&&` False True ≡ False + +let {- + `||` m n + + computes `m || n` + -} `||` + : Bool → Bool → Bool + = λ(m : Bool) → λ(n : Bool) → m || n + +let example8 = assert : `||` False True ≡ True + +in { `+`, `*`, `++`, `#`, `==`, `!=`, `&&`, `||` } diff --git a/dhall/Prelude/Optional/all b/dhall/Prelude/Optional/all new file mode 100644 index 0000000..6b1f082 --- /dev/null +++ b/dhall/Prelude/Optional/all @@ -0,0 +1,3 @@ + missing + sha256:a303004b6def0a2a05bf5f0a8d54e84dd45d8bef581789186ac04924956a1695 +? ./all.dhall diff --git a/dhall/Prelude/Optional/all.dhall b/dhall/Prelude/Optional/all.dhall new file mode 100644 index 0000000..154f038 --- /dev/null +++ b/dhall/Prelude/Optional/all.dhall @@ -0,0 +1,16 @@ +{-| +Returns `False` if the supplied function returns `False` for a present element +and `True` otherwise: +-} +let all + : ∀(a : Type) → (a → Bool) → Optional a → Bool + = λ(a : Type) → + λ(f : a → Bool) → + λ(xs : Optional a) → + merge { Some = f, None = True } xs + +let example0 = assert : all Natural Natural/even (Some 3) ≡ False + +let example1 = assert : all Natural Natural/even (None Natural) ≡ True + +in all diff --git a/dhall/Prelude/Optional/any b/dhall/Prelude/Optional/any new file mode 100644 index 0000000..bf25972 --- /dev/null +++ b/dhall/Prelude/Optional/any @@ -0,0 +1,3 @@ + missing + sha256:96a5cf4f31b3c598b09161dd3082f0a09f4328a4cefda6a7e09894b37b17b435 +? ./any.dhall diff --git a/dhall/Prelude/Optional/any.dhall b/dhall/Prelude/Optional/any.dhall new file mode 100644 index 0000000..ef67805 --- /dev/null +++ b/dhall/Prelude/Optional/any.dhall @@ -0,0 +1,16 @@ +{-| +Returns `True` if the supplied function returns `True` for a present element and +`False` otherwise +-} +let any + : ∀(a : Type) → (a → Bool) → Optional a → Bool + = λ(a : Type) → + λ(f : a → Bool) → + λ(xs : Optional a) → + merge { Some = f, None = False } xs + +let example0 = assert : any Natural Natural/even (Some 2) ≡ True + +let example1 = assert : any Natural Natural/even (None Natural) ≡ False + +in any diff --git a/dhall/Prelude/Optional/build b/dhall/Prelude/Optional/build new file mode 100644 index 0000000..859e7a2 --- /dev/null +++ b/dhall/Prelude/Optional/build @@ -0,0 +1,3 @@ + missing + sha256:28e61294bf2dd59dc57cf74f719d1568e60b5ba46c28eac586bc937eff4a2af1 +? ./build.dhall diff --git a/dhall/Prelude/Optional/build.dhall b/dhall/Prelude/Optional/build.dhall new file mode 100644 index 0000000..b26d2d1 --- /dev/null +++ b/dhall/Prelude/Optional/build.dhall @@ -0,0 +1,41 @@ +--| `build` is the inverse of `fold` +let build + : ∀(a : Type) → + ( ∀(optional : Type) → + ∀(some : a → optional) → + ∀(none : optional) → + optional + ) → + Optional a + = λ(a : Type) → + λ ( build + : ∀(optional : Type) → + ∀(some : a → optional) → + ∀(none : optional) → + optional + ) → + build (Optional a) (λ(x : a) → Some x) (None a) + +let example0 = + assert + : build + Natural + ( λ(optional : Type) → + λ(some : Natural → optional) → + λ(none : optional) → + some 1 + ) + ≡ Some 1 + +let example1 = + assert + : build + Natural + ( λ(optional : Type) → + λ(some : Natural → optional) → + λ(none : optional) → + none + ) + ≡ None Natural + +in build diff --git a/dhall/Prelude/Optional/concat b/dhall/Prelude/Optional/concat new file mode 100644 index 0000000..4337f78 --- /dev/null +++ b/dhall/Prelude/Optional/concat @@ -0,0 +1,3 @@ + missing + sha256:b7736bd3ebeab14c3912dfb534d0c970a025b001d06c2d5461d4b0e289e3cb7a +? ./concat.dhall diff --git a/dhall/Prelude/Optional/concat.dhall b/dhall/Prelude/Optional/concat.dhall new file mode 100644 index 0000000..4036848 --- /dev/null +++ b/dhall/Prelude/Optional/concat.dhall @@ -0,0 +1,14 @@ +--| Flatten two `Optional` layers into a single `Optional` layer +let concat + : ∀(a : Type) → Optional (Optional a) → Optional a + = λ(a : Type) → + λ(x : Optional (Optional a)) → + merge { Some = λ(y : Optional a) → y, None = None a } x + +let example0 = assert : concat Natural (Some (Some 1)) ≡ Some 1 + +let example1 = assert : concat Natural (Some (None Natural)) ≡ None Natural + +let example2 = assert : concat Natural (None (Optional Natural)) ≡ None Natural + +in concat diff --git a/dhall/Prelude/Optional/concatMap.dhall b/dhall/Prelude/Optional/concatMap.dhall new file mode 100644 index 0000000..59cd72e --- /dev/null +++ b/dhall/Prelude/Optional/concatMap.dhall @@ -0,0 +1,23 @@ +--| Transform the value with a function and flatten the resulting `Optional` +let concatMap + : ∀(a : Type) → ∀(b : Type) → (a → Optional b) → Optional a → Optional b + = λ(a : Type) → + λ(b : Type) → + λ(f : a → Optional b) → + λ(o : Optional a) → + merge { Some = f, None = None b } o + +let exampleFun + : Natural → Optional Natural + = λ(n : Natural) → if Natural/even n then Some (n + 1) else None Natural + +let example0 = + assert : concatMap Natural Natural exampleFun (Some 1) ≡ None Natural + +let example1 = assert : concatMap Natural Natural exampleFun (Some 2) ≡ Some 3 + +let example2 = + assert + : concatMap Natural Natural exampleFun (None Natural) ≡ None Natural + +in concatMap diff --git a/dhall/Prelude/Optional/default b/dhall/Prelude/Optional/default new file mode 100644 index 0000000..e90ebab --- /dev/null +++ b/dhall/Prelude/Optional/default @@ -0,0 +1,3 @@ + missing + sha256:5bd665b0d6605c374b3c4a7e2e2bd3b9c1e39323d41441149ed5e30d86e889ad +? ./default.dhall diff --git a/dhall/Prelude/Optional/default.dhall b/dhall/Prelude/Optional/default.dhall new file mode 100644 index 0000000..49dbe3b --- /dev/null +++ b/dhall/Prelude/Optional/default.dhall @@ -0,0 +1,13 @@ +--| Unpack an `Optional`, returning the default when it's `None`. +let default + : ∀(a : Type) → a → Optional a → a + = λ(a : Type) → + λ(default : a) → + λ(o : Optional a) → + merge { Some = λ(x : a) → x, None = default } o + +let example0 = assert : default Bool False (None Bool) ≡ False + +let example1 = assert : default Bool False (Some True) ≡ True + +in default diff --git a/dhall/Prelude/Optional/equal b/dhall/Prelude/Optional/equal new file mode 100644 index 0000000..e67af6f --- /dev/null +++ b/dhall/Prelude/Optional/equal @@ -0,0 +1,3 @@ + missing + sha256:5411888399fe9c6720f7f3b59caf5eff3e8e8c30402d09f34e46a4457649a35a +? ./equal.dhall diff --git a/dhall/Prelude/Optional/equal.dhall b/dhall/Prelude/Optional/equal.dhall new file mode 100644 index 0000000..33909c8 --- /dev/null +++ b/dhall/Prelude/Optional/equal.dhall @@ -0,0 +1,24 @@ +let Optional/fold = + missing + sha256:c5b9d72f6f62bdaa0e196ac1c742cc175cd67a717b880fb8aec1333a5a4132cf + ? ./fold.dhall + +let Optional/null = + missing + sha256:3871180b87ecaba8b53fffb2a8b52d3fce98098fab09a6f759358b9e8042eedc + ? ./null.dhall + +let equal + : forall (a : Type) -> (a -> a -> Bool) -> Optional a -> Optional a -> Bool + = \(a : Type) -> + \(compare : a -> a -> Bool) -> + \(ox : Optional a) -> + \(oy : Optional a) -> + Optional/fold + a + ox + Bool + (\(x : a) -> Optional/fold a oy Bool (compare x) False) + (Optional/null a oy) + +in equal diff --git a/dhall/Prelude/Optional/filter b/dhall/Prelude/Optional/filter new file mode 100644 index 0000000..66d64bd --- /dev/null +++ b/dhall/Prelude/Optional/filter @@ -0,0 +1,3 @@ + missing + sha256:54f0a487d578801819613fe000050c038c632edf1f9ccc57677e98ae0ef56b83 +? ./filter.dhall diff --git a/dhall/Prelude/Optional/filter.dhall b/dhall/Prelude/Optional/filter.dhall new file mode 100644 index 0000000..c0caa2d --- /dev/null +++ b/dhall/Prelude/Optional/filter.dhall @@ -0,0 +1,29 @@ +--| Only keep an `Optional` element if the supplied function returns `True` +let filter + : ∀(a : Type) → (a → Bool) → Optional a → Optional a + = λ(a : Type) → + λ(f : a → Bool) → + λ(xs : Optional a) → + ( λ(a : Type) → + λ ( build + : ∀(optional : Type) → + ∀(some : a → optional) → + ∀(none : optional) → + optional + ) → + build (Optional a) (λ(x : a) → Some x) (None a) + ) + a + ( λ(optional : Type) → + λ(some : a → optional) → + λ(none : optional) → + merge + { Some = λ(x : a) → if f x then some x else none, None = none } + xs + ) + +let example0 = assert : filter Natural Natural/even (Some 2) ≡ Some 2 + +let example1 = assert : filter Natural Natural/odd (Some 2) ≡ None Natural + +in filter diff --git a/dhall/Prelude/Optional/fold b/dhall/Prelude/Optional/fold new file mode 100644 index 0000000..24eb3fe --- /dev/null +++ b/dhall/Prelude/Optional/fold @@ -0,0 +1,3 @@ + missing + sha256:c5b9d72f6f62bdaa0e196ac1c742cc175cd67a717b880fb8aec1333a5a4132cf +? ./fold.dhall diff --git a/dhall/Prelude/Optional/fold.dhall b/dhall/Prelude/Optional/fold.dhall new file mode 100644 index 0000000..49c4a55 --- /dev/null +++ b/dhall/Prelude/Optional/fold.dhall @@ -0,0 +1,20 @@ +--| `fold` is the primitive function for consuming `Optional` values +let fold + : ∀(a : Type) → + Optional a → + ∀(optional : Type) → + ∀(some : a → optional) → + ∀(none : optional) → + optional + = λ(a : Type) → + λ(o : Optional a) → + λ(optional : Type) → + λ(some : a → optional) → + λ(none : optional) → + merge { Some = some, None = none } o + +let example0 = assert : fold Natural (Some 2) Text Natural/show "0" ≡ "2" + +let example1 = assert : fold Natural (None Natural) Text Natural/show "0" ≡ "0" + +in fold diff --git a/dhall/Prelude/Optional/head b/dhall/Prelude/Optional/head new file mode 100644 index 0000000..9e31bea --- /dev/null +++ b/dhall/Prelude/Optional/head @@ -0,0 +1,3 @@ + missing + sha256:4f256c9338b60a1933f41f2a8fafd861930a1e41770a644cdbac0622676fa34c +? ./head.dhall diff --git a/dhall/Prelude/Optional/head.dhall b/dhall/Prelude/Optional/head.dhall new file mode 100644 index 0000000..01c6ec0 --- /dev/null +++ b/dhall/Prelude/Optional/head.dhall @@ -0,0 +1,24 @@ +--| Returns the first non-empty `Optional` value in a `List` +let head + : ∀(a : Type) → List (Optional a) → Optional a + = λ(a : Type) → + λ(xs : List (Optional a)) → + List/fold + (Optional a) + xs + (Optional a) + ( λ(l : Optional a) → + λ(r : Optional a) → + merge { Some = λ(x : a) → Some x, None = r } l + ) + (None a) + +let example0 = assert : head Natural [ None Natural, Some 1, Some 2 ] ≡ Some 1 + +let example1 = + assert : head Natural [ None Natural, None Natural ] ≡ None Natural + +let example2 = + assert : head Natural ([] : List (Optional Natural)) ≡ None Natural + +in head diff --git a/dhall/Prelude/Optional/last b/dhall/Prelude/Optional/last new file mode 100644 index 0000000..653068e --- /dev/null +++ b/dhall/Prelude/Optional/last @@ -0,0 +1,3 @@ + missing + sha256:50400771ae19e9b75efa6581feec318ae1ade0b6a60e215df428c66c4b052707 +? ./last.dhall diff --git a/dhall/Prelude/Optional/last.dhall b/dhall/Prelude/Optional/last.dhall new file mode 100644 index 0000000..6131b06 --- /dev/null +++ b/dhall/Prelude/Optional/last.dhall @@ -0,0 +1,24 @@ +--| Returns the last non-empty `Optional` value in a `List` +let last + : ∀(a : Type) → List (Optional a) → Optional a + = λ(a : Type) → + λ(xs : List (Optional a)) → + List/fold + (Optional a) + xs + (Optional a) + ( λ(l : Optional a) → + λ(r : Optional a) → + merge { Some = λ(x : a) → Some x, None = l } r + ) + (None a) + +let example0 = assert : last Natural [ None Natural, Some 1, Some 2 ] ≡ Some 2 + +let example1 = + assert : last Natural [ None Natural, None Natural ] ≡ None Natural + +let example2 = + assert : last Natural ([] : List (Optional Natural)) ≡ None Natural + +in last diff --git a/dhall/Prelude/Optional/length b/dhall/Prelude/Optional/length new file mode 100644 index 0000000..a8629f1 --- /dev/null +++ b/dhall/Prelude/Optional/length @@ -0,0 +1,3 @@ + missing + sha256:f168337c5244ded68c05ecf32ce068b6b87158881d07e87b8cb6853fc6982a85 +? ./length.dhall diff --git a/dhall/Prelude/Optional/length.dhall b/dhall/Prelude/Optional/length.dhall new file mode 100644 index 0000000..8d678c7 --- /dev/null +++ b/dhall/Prelude/Optional/length.dhall @@ -0,0 +1,14 @@ +{-| +Returns `1` if the `Optional` value is present and `0` if the value is absent +-} +let length + : ∀(a : Type) → Optional a → Natural + = λ(a : Type) → + λ(xs : Optional a) → + merge { Some = λ(_ : a) → 1, None = 0 } xs + +let example0 = assert : length Natural (Some 2) ≡ 1 + +let example1 = assert : length Natural (None Natural) ≡ 0 + +in length diff --git a/dhall/Prelude/Optional/map b/dhall/Prelude/Optional/map new file mode 100644 index 0000000..0255f74 --- /dev/null +++ b/dhall/Prelude/Optional/map @@ -0,0 +1,3 @@ + missing + sha256:501534192d988218d43261c299cc1d1e0b13d25df388937add784778ab0054fa +? ./map.dhall diff --git a/dhall/Prelude/Optional/map.dhall b/dhall/Prelude/Optional/map.dhall new file mode 100644 index 0000000..9951e8e --- /dev/null +++ b/dhall/Prelude/Optional/map.dhall @@ -0,0 +1,14 @@ +--| Transform an `Optional` value with a function +let map + : ∀(a : Type) → ∀(b : Type) → (a → b) → Optional a → Optional b + = λ(a : Type) → + λ(b : Type) → + λ(f : a → b) → + λ(o : Optional a) → + merge { Some = λ(x : a) → Some (f x), None = None b } o + +let example0 = assert : map Natural Bool Natural/even (Some 3) ≡ Some False + +let example1 = assert : map Natural Bool Natural/even (None Natural) ≡ None Bool + +in map diff --git a/dhall/Prelude/Optional/null b/dhall/Prelude/Optional/null new file mode 100644 index 0000000..c7387e0 --- /dev/null +++ b/dhall/Prelude/Optional/null @@ -0,0 +1,3 @@ + missing + sha256:3871180b87ecaba8b53fffb2a8b52d3fce98098fab09a6f759358b9e8042eedc +? ./null.dhall diff --git a/dhall/Prelude/Optional/null.dhall b/dhall/Prelude/Optional/null.dhall new file mode 100644 index 0000000..4df3113 --- /dev/null +++ b/dhall/Prelude/Optional/null.dhall @@ -0,0 +1,12 @@ +--| Returns `True` if the `Optional` value is absent and `False` if present +let null + : ∀(a : Type) → Optional a → Bool + = λ(a : Type) → + λ(xs : Optional a) → + merge { Some = λ(_ : a) → False, None = True } xs + +let example0 = assert : null Natural (Some 2) ≡ False + +let example1 = assert : null Natural (None Natural) ≡ True + +in null diff --git a/dhall/Prelude/Optional/package.dhall b/dhall/Prelude/Optional/package.dhall new file mode 100644 index 0000000..449b2c6 --- /dev/null +++ b/dhall/Prelude/Optional/package.dhall @@ -0,0 +1,65 @@ +{ all = + missing + sha256:a303004b6def0a2a05bf5f0a8d54e84dd45d8bef581789186ac04924956a1695 + ? ./all.dhall +, any = + missing + sha256:96a5cf4f31b3c598b09161dd3082f0a09f4328a4cefda6a7e09894b37b17b435 + ? ./any.dhall +, build = + missing + sha256:28e61294bf2dd59dc57cf74f719d1568e60b5ba46c28eac586bc937eff4a2af1 + ? ./build.dhall +, concat = + missing + sha256:b7736bd3ebeab14c3912dfb534d0c970a025b001d06c2d5461d4b0e289e3cb7a + ? ./concat.dhall +, concatMap = + missing + sha256:c06ae93e900a99299c9b4ec4912ca5395a0103ea88292205b08dd7e345632818 + ? ./concatMap.dhall +, default = + missing + sha256:5bd665b0d6605c374b3c4a7e2e2bd3b9c1e39323d41441149ed5e30d86e889ad + ? ./default.dhall +, equal = + missing + sha256:5411888399fe9c6720f7f3b59caf5eff3e8e8c30402d09f34e46a4457649a35a + ? ./equal.dhall +, filter = + missing + sha256:54f0a487d578801819613fe000050c038c632edf1f9ccc57677e98ae0ef56b83 + ? ./filter.dhall +, fold = + missing + sha256:c5b9d72f6f62bdaa0e196ac1c742cc175cd67a717b880fb8aec1333a5a4132cf + ? ./fold.dhall +, head = + missing + sha256:4f256c9338b60a1933f41f2a8fafd861930a1e41770a644cdbac0622676fa34c + ? ./head.dhall +, last = + missing + sha256:50400771ae19e9b75efa6581feec318ae1ade0b6a60e215df428c66c4b052707 + ? ./last.dhall +, length = + missing + sha256:f168337c5244ded68c05ecf32ce068b6b87158881d07e87b8cb6853fc6982a85 + ? ./length.dhall +, map = + missing + sha256:501534192d988218d43261c299cc1d1e0b13d25df388937add784778ab0054fa + ? ./map.dhall +, null = + missing + sha256:3871180b87ecaba8b53fffb2a8b52d3fce98098fab09a6f759358b9e8042eedc + ? ./null.dhall +, toList = + missing + sha256:d78f160c619119ef12389e48a629ce293d69f7624c8d016b7a4767ab400344c4 + ? ./toList.dhall +, unzip = + missing + sha256:d016c01ba91657a2f35609aa29087963d0f506bab0f41d5e8b7cd289dff39708 + ? ./unzip.dhall +} diff --git a/dhall/Prelude/Optional/toList b/dhall/Prelude/Optional/toList new file mode 100644 index 0000000..d5ee916 --- /dev/null +++ b/dhall/Prelude/Optional/toList @@ -0,0 +1,3 @@ + missing + sha256:d78f160c619119ef12389e48a629ce293d69f7624c8d016b7a4767ab400344c4 +? ./toList.dhall diff --git a/dhall/Prelude/Optional/toList.dhall b/dhall/Prelude/Optional/toList.dhall new file mode 100644 index 0000000..3d1ac83 --- /dev/null +++ b/dhall/Prelude/Optional/toList.dhall @@ -0,0 +1,12 @@ +--| Convert an `Optional` value into the equivalent `List` +let toList + : ∀(a : Type) → Optional a → List a + = λ(a : Type) → + λ(o : Optional a) → + merge { Some = λ(x : a) → [ x ] : List a, None = [] : List a } o + +let example0 = assert : toList Natural (Some 1) ≡ [ 1 ] + +let example1 = assert : toList Natural (None Natural) ≡ ([] : List Natural) + +in toList diff --git a/dhall/Prelude/Optional/unzip b/dhall/Prelude/Optional/unzip new file mode 100644 index 0000000..cb9f380 --- /dev/null +++ b/dhall/Prelude/Optional/unzip @@ -0,0 +1,3 @@ + missing + sha256:d016c01ba91657a2f35609aa29087963d0f506bab0f41d5e8b7cd289dff39708 +? ./unzip.dhall diff --git a/dhall/Prelude/Optional/unzip.dhall b/dhall/Prelude/Optional/unzip.dhall new file mode 100644 index 0000000..a8824af --- /dev/null +++ b/dhall/Prelude/Optional/unzip.dhall @@ -0,0 +1,30 @@ +--| Unzip an `Optional` value into two separate `Optional` values +let unzip + : ∀(a : Type) → + ∀(b : Type) → + Optional { _1 : a, _2 : b } → + { _1 : Optional a, _2 : Optional b } + = λ(a : Type) → + λ(b : Type) → + λ(xs : Optional { _1 : a, _2 : b }) → + { _1 = + merge + { Some = λ(x : { _1 : a, _2 : b }) → Some x._1, None = None a } + xs + , _2 = + merge + { Some = λ(x : { _1 : a, _2 : b }) → Some x._2, None = None b } + xs + } + +let example0 = + assert + : unzip Text Bool (Some { _1 = "ABC", _2 = True }) + ≡ { _1 = Some "ABC", _2 = Some True } + +let example1 = + assert + : unzip Text Bool (None { _1 : Text, _2 : Bool }) + ≡ { _1 = None Text, _2 = None Bool } + +in unzip diff --git a/dhall/Prelude/README.md b/dhall/Prelude/README.md new file mode 100644 index 0000000..94b9665 --- /dev/null +++ b/dhall/Prelude/README.md @@ -0,0 +1,79 @@ +# Prelude + +This package contains useful utilities for getting started with the Dhall +configuration language. The Prelude is unique in that changes are approved by +the same process as changes to the language standard. + +## Usage + +The Prelude is hosted at: + +* [https://prelude.dhall-lang.org/](https://prelude.dhall-lang.org) + +... which you can use in several ways: + +* To browse the latest release of the Prelude package, you can visit: + + [https://prelude.dhall-lang.org/](https://prelude.dhall-lang.org) + +* To import a specific expression add the path to that expression to the URL + + For example, the URL for the `./Bool/not` expression is: + + [https://prelude.dhall-lang.org/Bool/not](https://prelude.dhall-lang.org/Bool/not) + + Here is an example of using the [`./Bool/not`](./Bool/not) expression: + + ```dhall + let Bool/not = https://prelude.dhall-lang.org/Bool/not + + in Bool/not True + ``` + +* To import the entire Prelude as a nested record, use the following import + within your Dhall code: + + [https://prelude.dhall-lang.org/package.dhall](https://prelude.dhall-lang.org/package.dhall) + + Here is an example of accessing the [`./Bool/not`](./Bool/not) expression as a + field of that record: + + ```dhall + let Prelude = https://prelude.dhall-lang.org/package.dhall + + in Prelude.Bool.not True + ``` + +* You can pin an expression to a specific version of the Prelude by prefixing the + path with the Prelude version + + For example, you could use the following URL to import version `10.0.0` of the + Prelude: + + [https://prelude.dhall-lang.org/v10.0.0/package.dhall](https://prelude.dhall-lang.org/v10.0.0/package.dhall) + + This also works for individual expressions, too, such as: + + [https://prelude.dhall-lang.org/v10.0.0/Bool/not](https://prelude.dhall-lang.org/v10.0.0/Bool/not) + + ... or for browsing a specific release of the Prelude: + + [https://prelude.dhall-lang.org/v10.0.0](https://prelude.dhall-lang.org/v10.0.0) + +The `prelude.dhall-lang.org` domain is CORS-enabled so the Prelude can be used +as a transitive import of other packages without violating the Dhall language's +CORS check. + +## Scope + +There is no hard rule for what belongs in the Prelude, but we can document what +we have included so far: + +* General purpose utilities (like [`./List/filter`](./List/filter)) + +* Re-exports of language built-ins (like [`./Natural/fold`](./Natural/fold)) + +* Integrations with other configuration formats (like [`./JSON/package.dhall`](./JSON/package.dhall)) + +The [contributing instructions](../.github/CONTRIBUTING.md#how-do-i-change-the-language) +provide more details about how to discuss or propose changes if you would like to contribute to the Prelude. diff --git a/dhall/Prelude/Text/concat b/dhall/Prelude/Text/concat new file mode 100644 index 0000000..3f3ff5c --- /dev/null +++ b/dhall/Prelude/Text/concat @@ -0,0 +1,3 @@ + missing + sha256:731265b0288e8a905ecff95c97333ee2db614c39d69f1514cb8eed9259745fc0 +? ./concat.dhall diff --git a/dhall/Prelude/Text/concat.dhall b/dhall/Prelude/Text/concat.dhall new file mode 100644 index 0000000..6acc016 --- /dev/null +++ b/dhall/Prelude/Text/concat.dhall @@ -0,0 +1,11 @@ +--| Concatenate all the `Text` values in a `List` +let concat + : List Text → Text + = λ(xs : List Text) → + List/fold Text xs Text (λ(x : Text) → λ(y : Text) → x ++ y) "" + +let example0 = assert : concat [ "ABC", "DEF", "GHI" ] ≡ "ABCDEFGHI" + +let example1 = assert : concat ([] : List Text) ≡ "" + +in concat diff --git a/dhall/Prelude/Text/concatMap b/dhall/Prelude/Text/concatMap new file mode 100644 index 0000000..66ecf59 --- /dev/null +++ b/dhall/Prelude/Text/concatMap @@ -0,0 +1,3 @@ + missing + sha256:7a0b0b99643de69d6f94ba49441cd0fa0507cbdfa8ace0295f16097af37e226f +? ./concatMap.dhall diff --git a/dhall/Prelude/Text/concatMap.dhall b/dhall/Prelude/Text/concatMap.dhall new file mode 100644 index 0000000..2defcfa --- /dev/null +++ b/dhall/Prelude/Text/concatMap.dhall @@ -0,0 +1,22 @@ +--| Transform each value in a `List` into `Text` and concatenate the result +let concatMap + : ∀(a : Type) → (a → Text) → List a → Text + = λ(a : Type) → + λ(f : a → Text) → + λ(xs : List a) → + List/fold a xs Text (λ(x : a) → λ(y : Text) → f x ++ y) "" + +let example0 = + assert + : concatMap Natural (λ(n : Natural) → "${Natural/show n} ") [ 0, 1, 2 ] + ≡ "0 1 2 " + +let example1 = + assert + : concatMap + Natural + (λ(n : Natural) → "${Natural/show n} ") + ([] : List Natural) + ≡ "" + +in concatMap diff --git a/dhall/Prelude/Text/concatMapSep b/dhall/Prelude/Text/concatMapSep new file mode 100644 index 0000000..30ef39d --- /dev/null +++ b/dhall/Prelude/Text/concatMapSep @@ -0,0 +1,3 @@ + missing + sha256:c272aca80a607bc5963d1fcb38819e7e0d3e72ac4d02b1183b1afb6a91340840 +? ./concatMapSep.dhall diff --git a/dhall/Prelude/Text/concatMapSep.dhall b/dhall/Prelude/Text/concatMapSep.dhall new file mode 100644 index 0000000..8e23b70 --- /dev/null +++ b/dhall/Prelude/Text/concatMapSep.dhall @@ -0,0 +1,38 @@ +{-| +Transform each value in a `List` to `Text` and then concatenate them with a +separator in between each value +-} +let Status = < Empty | NonEmpty : Text > + +let concatMapSep + : ∀(separator : Text) → ∀(a : Type) → (a → Text) → List a → Text + = λ(separator : Text) → + λ(a : Type) → + λ(f : a → Text) → + λ(elements : List a) → + let status = + List/fold + a + elements + Status + ( λ(x : a) → + λ(status : Status) → + merge + { Empty = Status.NonEmpty (f x) + , NonEmpty = + λ(result : Text) → + Status.NonEmpty (f x ++ separator ++ result) + } + status + ) + Status.Empty + + in merge { Empty = "", NonEmpty = λ(result : Text) → result } status + +let example0 = + assert : concatMapSep ", " Natural Natural/show [ 0, 1, 2 ] ≡ "0, 1, 2" + +let example1 = + assert : concatMapSep ", " Natural Natural/show ([] : List Natural) ≡ "" + +in concatMapSep diff --git a/dhall/Prelude/Text/concatSep b/dhall/Prelude/Text/concatSep new file mode 100644 index 0000000..2fba656 --- /dev/null +++ b/dhall/Prelude/Text/concatSep @@ -0,0 +1,3 @@ + missing + sha256:e4401d69918c61b92a4c0288f7d60a6560ca99726138ed8ebc58dca2cd205e58 +? ./concatSep.dhall diff --git a/dhall/Prelude/Text/concatSep.dhall b/dhall/Prelude/Text/concatSep.dhall new file mode 100644 index 0000000..9e2959e --- /dev/null +++ b/dhall/Prelude/Text/concatSep.dhall @@ -0,0 +1,31 @@ +--| Concatenate a `List` of `Text` values with a separator in between each value +let Status = < Empty | NonEmpty : Text > + +let concatSep + : ∀(separator : Text) → ∀(elements : List Text) → Text + = λ(separator : Text) → + λ(elements : List Text) → + let status = + List/fold + Text + elements + Status + ( λ(element : Text) → + λ(status : Status) → + merge + { Empty = Status.NonEmpty element + , NonEmpty = + λ(result : Text) → + Status.NonEmpty (element ++ separator ++ result) + } + status + ) + Status.Empty + + in merge { Empty = "", NonEmpty = λ(result : Text) → result } status + +let example0 = assert : concatSep ", " [ "ABC", "DEF", "GHI" ] ≡ "ABC, DEF, GHI" + +let example1 = assert : concatSep ", " ([] : List Text) ≡ "" + +in concatSep diff --git a/dhall/Prelude/Text/default b/dhall/Prelude/Text/default new file mode 100644 index 0000000..c7a072f --- /dev/null +++ b/dhall/Prelude/Text/default @@ -0,0 +1,3 @@ + missing + sha256:f532c8891b1e427d90a6cc07cf7e793a4c84b0765e1bfe69f186ee2ec91c1edf +? ./default.dhall diff --git a/dhall/Prelude/Text/default.dhall b/dhall/Prelude/Text/default.dhall new file mode 100644 index 0000000..6b87191 --- /dev/null +++ b/dhall/Prelude/Text/default.dhall @@ -0,0 +1,10 @@ +--| Unwrap an `Optional` `Text` value, defaulting `None` to `""` +let default + : Optional Text → Text + = λ(o : Optional Text) → merge { Some = λ(t : Text) → t, None = "" } o + +let example0 = assert : default (Some "ABC") ≡ "ABC" + +let example1 = assert : default (None Text) ≡ "" + +in default diff --git a/dhall/Prelude/Text/defaultMap b/dhall/Prelude/Text/defaultMap new file mode 100644 index 0000000..e105f69 --- /dev/null +++ b/dhall/Prelude/Text/defaultMap @@ -0,0 +1,3 @@ + missing + sha256:3a3fa1264f6198800c27483cb144de2c5366484876d60b9c739a710ce0288588 +? ./defaultMap.dhall diff --git a/dhall/Prelude/Text/defaultMap.dhall b/dhall/Prelude/Text/defaultMap.dhall new file mode 100644 index 0000000..e181211 --- /dev/null +++ b/dhall/Prelude/Text/defaultMap.dhall @@ -0,0 +1,13 @@ +--| Transform the value in an `Optional` into `Text`, defaulting `None` to `""` +let defaultMap + : ∀(a : Type) → (a → Text) → Optional a → Text + = λ(a : Type) → + λ(f : a → Text) → + λ(o : Optional a) → + merge { Some = f, None = "" } o + +let example0 = assert : defaultMap Natural Natural/show (Some 0) ≡ "0" + +let example1 = assert : defaultMap Natural Natural/show (None Natural) ≡ "" + +in defaultMap diff --git a/dhall/Prelude/Text/lowerASCII.dhall b/dhall/Prelude/Text/lowerASCII.dhall new file mode 100644 index 0000000..a96ae8e --- /dev/null +++ b/dhall/Prelude/Text/lowerASCII.dhall @@ -0,0 +1,56 @@ +{-| +Lowercase all ASCII characters + +Note that this will also lowercase decomposed Unicode characters that contain +codepoints in the ASCII range +-} +let lowerASCII + : Text → Text + = List/fold + (Text → Text) + [ Text/replace "A" "a" + , Text/replace "B" "b" + , Text/replace "C" "c" + , Text/replace "D" "d" + , Text/replace "E" "e" + , Text/replace "F" "f" + , Text/replace "G" "g" + , Text/replace "H" "h" + , Text/replace "I" "i" + , Text/replace "J" "j" + , Text/replace "K" "k" + , Text/replace "L" "l" + , Text/replace "M" "m" + , Text/replace "N" "n" + , Text/replace "O" "o" + , Text/replace "P" "p" + , Text/replace "Q" "q" + , Text/replace "R" "r" + , Text/replace "S" "s" + , Text/replace "T" "t" + , Text/replace "U" "u" + , Text/replace "V" "v" + , Text/replace "W" "w" + , Text/replace "X" "x" + , Text/replace "Y" "y" + , Text/replace "Z" "z" + ] + Text + (λ(replacement : Text → Text) → replacement) + +let example0 = assert : lowerASCII "ABCdef" ≡ "abcdef" + +let -- This does not lowercase precomposed Unicode characters + -- + -- • The `Á` in the following example is U+00C1 + example1 = + assert : lowerASCII "Á" ≡ "Á" + +let -- … but this does lowercase decomposed Unicode characters + -- + -- • The `Á` in the following example is U+0041 U+0301 + -- • The `á` in the following example is U+0061 U+0301 + example1 = + assert : lowerASCII "Á" ≡ "á" + +in lowerASCII diff --git a/dhall/Prelude/Text/package.dhall b/dhall/Prelude/Text/package.dhall new file mode 100644 index 0000000..ada3e06 --- /dev/null +++ b/dhall/Prelude/Text/package.dhall @@ -0,0 +1,53 @@ +{ concat = + missing + sha256:731265b0288e8a905ecff95c97333ee2db614c39d69f1514cb8eed9259745fc0 + ? ./concat.dhall +, concatMap = + missing + sha256:7a0b0b99643de69d6f94ba49441cd0fa0507cbdfa8ace0295f16097af37e226f + ? ./concatMap.dhall +, concatMapSep = + missing + sha256:c272aca80a607bc5963d1fcb38819e7e0d3e72ac4d02b1183b1afb6a91340840 + ? ./concatMapSep.dhall +, concatSep = + missing + sha256:e4401d69918c61b92a4c0288f7d60a6560ca99726138ed8ebc58dca2cd205e58 + ? ./concatSep.dhall +, default = + missing + sha256:f532c8891b1e427d90a6cc07cf7e793a4c84b0765e1bfe69f186ee2ec91c1edf + ? ./default.dhall +, defaultMap = + missing + sha256:3a3fa1264f6198800c27483cb144de2c5366484876d60b9c739a710ce0288588 + ? ./defaultMap.dhall +, lowerASCII = + missing + sha256:26b076651120b907e869396bd3dc16271f2e12433062b2f26f296968a69515e7 + ? ./lowerASCII.dhall +, replace = + missing + sha256:7d132df0e091a43817bba8afa06d1bb487ee51c091430404ad6f8c78bc0328a6 + ? ./replace.dhall +, replicate = + missing + sha256:1b398b1d464b3a6c7264a690ac3cacb443b5683b43348c859d68e7c2cb925c4f + ? ./replicate.dhall +, shell-escape = + missing + sha256:d53521b3f478cb18a7d63730bc0e3153c2124b70d6ac9a1f610ce7db67cfc7a2 + ? ./shell-escape.dhall +, show = + missing + sha256:c9dc5de3e5f32872dbda57166804865e5e80785abe358ff61f1d8ac45f1f4784 + ? ./show.dhall +, spaces = + missing + sha256:fccfd4f26601e006bf6a79ca948dbd37c676cdd0db439554447320293d23b3dc + ? ./spaces.dhall +, upperASCII = + missing + sha256:45ae4fbd814b0474e65c28a4ee92b23b979892fa5bb73730bc99675ae790ca29 + ? ./upperASCII.dhall +} diff --git a/dhall/Prelude/Text/replace.dhall b/dhall/Prelude/Text/replace.dhall new file mode 100644 index 0000000..ba01e91 --- /dev/null +++ b/dhall/Prelude/Text/replace.dhall @@ -0,0 +1,14 @@ +{- +Replace a section of `Text` with another inside a `Text` literal. +-} +let replace + : ∀(needle : Text) → ∀(replacement : Text) → ∀(haystack : Text) → Text + = Text/replace + +let example0 = assert : replace "-" "_" "foo-bar" ≡ "foo_bar" + +let example1 = assert : replace "💣" "💥" "💣💣💣" ≡ "💥💥💥" + +let example2 = assert : replace "👨" "👩" "👨‍👩‍👧‍👦" ≡ "👩‍👩‍👧‍👦" + +in replace diff --git a/dhall/Prelude/Text/replicate b/dhall/Prelude/Text/replicate new file mode 100644 index 0000000..858d506 --- /dev/null +++ b/dhall/Prelude/Text/replicate @@ -0,0 +1,3 @@ + missing + sha256:1b398b1d464b3a6c7264a690ac3cacb443b5683b43348c859d68e7c2cb925c4f +? ./replicate.dhall diff --git a/dhall/Prelude/Text/replicate.dhall b/dhall/Prelude/Text/replicate.dhall new file mode 100644 index 0000000..b1439be --- /dev/null +++ b/dhall/Prelude/Text/replicate.dhall @@ -0,0 +1,20 @@ +--| Build a Text by copying the given Text the specified number of times +let concat = + missing + sha256:731265b0288e8a905ecff95c97333ee2db614c39d69f1514cb8eed9259745fc0 + ? ./concat.dhall + +let List/replicate = + missing + sha256:d4250b45278f2d692302489ac3e78280acb238d27541c837ce46911ff3baa347 + ? ../List/replicate.dhall + +let replicate + : Natural → Text → Text + = λ(num : Natural) → λ(text : Text) → concat (List/replicate num Text text) + +let example0 = assert : replicate 3 "foo" ≡ "foofoofoo" + +let property = λ(text : Text) → assert : replicate 0 text ≡ "" + +in replicate diff --git a/dhall/Prelude/Text/shell-escape.dhall b/dhall/Prelude/Text/shell-escape.dhall new file mode 100644 index 0000000..ecabd14 --- /dev/null +++ b/dhall/Prelude/Text/shell-escape.dhall @@ -0,0 +1,16 @@ +{-| +Escape a Text value such that it can be used safely in shells. +The escaping is done by replacing all `'` with `'"'"'` and wraps that string in +single quotes. + +This works for all POSIX-compliant shells and some other shells like csh. +-} +let shell-escape + : Text -> Text + = \(xs : Text) -> "'${Text/replace "'" "'\"'\"'" xs}'" + +let example0 = assert : shell-escape "foo" === "'foo'" + +let example1 = assert : shell-escape "foo'bar" === "'foo'\"'\"'bar'" + +in shell-escape diff --git a/dhall/Prelude/Text/show b/dhall/Prelude/Text/show new file mode 100644 index 0000000..bfc2c52 --- /dev/null +++ b/dhall/Prelude/Text/show @@ -0,0 +1,3 @@ + missing + sha256:c9dc5de3e5f32872dbda57166804865e5e80785abe358ff61f1d8ac45f1f4784 +? ./show.dhall diff --git a/dhall/Prelude/Text/show.dhall b/dhall/Prelude/Text/show.dhall new file mode 100644 index 0000000..93858d9 --- /dev/null +++ b/dhall/Prelude/Text/show.dhall @@ -0,0 +1,19 @@ +{- +Render a `Text` literal as its own representation as Dhall source code (i.e. a +double-quoted string literal) +-} +let show + : Text → Text + = Text/show + +let example0 = assert : show "ABC" ≡ "\"ABC\"" + +let example1 = + assert + : show + '' + ${"\u0000"} $ \ + ${" "}☺'' + ≡ "\"\\u0000 \\u0024 \\\\ \\n ☺\"" + +in show diff --git a/dhall/Prelude/Text/spaces b/dhall/Prelude/Text/spaces new file mode 100644 index 0000000..88ea62e --- /dev/null +++ b/dhall/Prelude/Text/spaces @@ -0,0 +1,3 @@ + missing + sha256:fccfd4f26601e006bf6a79ca948dbd37c676cdd0db439554447320293d23b3dc +? ./spaces.dhall diff --git a/dhall/Prelude/Text/spaces.dhall b/dhall/Prelude/Text/spaces.dhall new file mode 100644 index 0000000..109e20a --- /dev/null +++ b/dhall/Prelude/Text/spaces.dhall @@ -0,0 +1,20 @@ +{-| +Return a Text with the number of spaces specified. + +This function is particularly helpful when trying to generate Text where +whitespace is significant, i.e. with nested indentation. +-} +let replicate = + missing + sha256:1b398b1d464b3a6c7264a690ac3cacb443b5683b43348c859d68e7c2cb925c4f + ? ./replicate.dhall + +let spaces + : Natural → Text + = λ(a : Natural) → replicate a " " + +let example0 = assert : spaces 1 ≡ " " + +let example1 = assert : spaces 0 ≡ "" + +in spaces diff --git a/dhall/Prelude/Text/upperASCII.dhall b/dhall/Prelude/Text/upperASCII.dhall new file mode 100644 index 0000000..4f17f1d --- /dev/null +++ b/dhall/Prelude/Text/upperASCII.dhall @@ -0,0 +1,56 @@ +{-| +Uppercase all ASCII characters + +Note that this will also uppercase decomposed Unicode characters that contain +codepoints in the ASCII range +-} +let upperASCII + : Text → Text + = List/fold + (Text → Text) + [ Text/replace "a" "A" + , Text/replace "b" "B" + , Text/replace "c" "C" + , Text/replace "d" "D" + , Text/replace "e" "E" + , Text/replace "f" "F" + , Text/replace "g" "G" + , Text/replace "h" "H" + , Text/replace "i" "I" + , Text/replace "j" "J" + , Text/replace "k" "K" + , Text/replace "l" "L" + , Text/replace "m" "M" + , Text/replace "n" "N" + , Text/replace "o" "O" + , Text/replace "p" "P" + , Text/replace "q" "Q" + , Text/replace "r" "R" + , Text/replace "s" "S" + , Text/replace "t" "T" + , Text/replace "u" "U" + , Text/replace "v" "V" + , Text/replace "w" "W" + , Text/replace "x" "X" + , Text/replace "y" "Y" + , Text/replace "z" "Z" + ] + Text + (λ(replacement : Text → Text) → replacement) + +let example0 = assert : upperASCII "ABCdef" ≡ "ABCDEF" + +let -- This does not uppercase precomposed Unicode characters + -- + -- • The `á` in the following example is U+00E1 + example1 = + assert : upperASCII "á" ≡ "á" + +let -- … but this does uppercase decomposed Unicode characters + -- + -- • The `Á` in the following example is U+0041 U+0301 + -- • The `á` in the following example is U+0061 U+0301 + example1 = + assert : upperASCII "á" ≡ "Á" + +in upperASCII diff --git a/dhall/Prelude/Time/package.dhall b/dhall/Prelude/Time/package.dhall new file mode 100644 index 0000000..f66410a --- /dev/null +++ b/dhall/Prelude/Time/package.dhall @@ -0,0 +1,5 @@ +{ show = + missing + sha256:8cabfe35dd0ee25ca65708105e860cbf4b789e0d73134aa905580799e2a46719 + ? ./show.dhall +} diff --git a/dhall/Prelude/Time/show.dhall b/dhall/Prelude/Time/show.dhall new file mode 100644 index 0000000..f739745 --- /dev/null +++ b/dhall/Prelude/Time/show.dhall @@ -0,0 +1,15 @@ +{- +Render a `Time` as `Text` using the same representation as Dhall source code +(i.e. `hh:mm:ss`) +-} +let show + : Time → Text + = Time/show + +let example0 = assert : show 03:15:47.90 ≡ "03:15:47.90" + +let example1 = assert : show 00:00:00 ≡ "00:00:00" + +let example2 = assert : show 11:59:59 ≡ "11:59:59" + +in show diff --git a/dhall/Prelude/TimeZone/package.dhall b/dhall/Prelude/TimeZone/package.dhall new file mode 100644 index 0000000..492e6bb --- /dev/null +++ b/dhall/Prelude/TimeZone/package.dhall @@ -0,0 +1,5 @@ +{ show = + missing + sha256:d183361f1c4c656bad3b170ec8b8d6705f564faebf94e4ef10c76061104ff061 + ? ./show.dhall +} diff --git a/dhall/Prelude/TimeZone/show.dhall b/dhall/Prelude/TimeZone/show.dhall new file mode 100644 index 0000000..c9eb83f --- /dev/null +++ b/dhall/Prelude/TimeZone/show.dhall @@ -0,0 +1,15 @@ +{- +Render a `TimeZone` as `Text` using the same representation as Dhall source code +(i.e. `±HH:MM`) +-} +let show + : TimeZone → Text + = TimeZone/show + +let example0 = assert : show +07:00 ≡ "+07:00" + +let example1 = assert : show +00:00 ≡ "+00:00" + +let example2 = assert : show -05:00 ≡ "-05:00" + +in show diff --git a/dhall/Prelude/XML/Type b/dhall/Prelude/XML/Type new file mode 100644 index 0000000..2702f69 --- /dev/null +++ b/dhall/Prelude/XML/Type @@ -0,0 +1,3 @@ + missing + sha256:ab91a0edaf0513e0083b1dfae5efa160adc99b0e589775a4a699ab77cce528a9 +? ./Type.dhall diff --git a/dhall/Prelude/XML/Type.dhall b/dhall/Prelude/XML/Type.dhall new file mode 100644 index 0000000..d891680 --- /dev/null +++ b/dhall/Prelude/XML/Type.dhall @@ -0,0 +1,65 @@ +{-| +Dhall encoding of an arbitrary XML element + +For example, the following XML element: + +``` +baz +``` + +... corresponds to the following Dhall expression: + + +``` +λ(XML : Type) + → λ ( xml + : { text : + Text → XML + , rawText : + Text → XML + , element : + { attributes : + List { mapKey : Text, mapValue : Text } + , content : + List XML + , name : + Text + } + → XML + } + ) + → xml.element + { attributes = + [ { mapKey = "n", mapValue = "1" } ] + , content = + [ xml.element + { attributes = + [] : List { mapKey : Text, mapValue : Text } + , content = + [ xml.text "baz" ] + , name = + "bar" + } + ] + , name = + "foo" + } +``` +-} +let XML/Type + : Type + = ∀(XML : Type) → + ∀ ( xml + : { text : Text → XML + , rawText : Text → XML + , element : + { attributes : List { mapKey : Text, mapValue : Text } + , content : List XML + , name : Text + } → + XML + } + ) → + XML + +in XML/Type diff --git a/dhall/Prelude/XML/attribute b/dhall/Prelude/XML/attribute new file mode 100644 index 0000000..3c5627f --- /dev/null +++ b/dhall/Prelude/XML/attribute @@ -0,0 +1,3 @@ + missing + sha256:f7b6c802ca5764d03d5e9a6e48d9cb167c01392f775d9c2c87b83cdaa60ea0cc +? ./attribute.dhall diff --git a/dhall/Prelude/XML/attribute.dhall b/dhall/Prelude/XML/attribute.dhall new file mode 100644 index 0000000..94bd4c4 --- /dev/null +++ b/dhall/Prelude/XML/attribute.dhall @@ -0,0 +1,6 @@ +--| Builds a key-value record with a Text key and value. +let attribute + : Text → Text → { mapKey : Text, mapValue : Text } + = λ(key : Text) → λ(value : Text) → { mapKey = key, mapValue = value } + +in attribute diff --git a/dhall/Prelude/XML/element b/dhall/Prelude/XML/element new file mode 100644 index 0000000..890547f --- /dev/null +++ b/dhall/Prelude/XML/element @@ -0,0 +1,3 @@ + missing + sha256:79266d604e147caf37e985581523b684f7bac66de0c93dd828841df3dfc445f9 +? ./element.dhall diff --git a/dhall/Prelude/XML/element.dhall b/dhall/Prelude/XML/element.dhall new file mode 100644 index 0000000..780e71a --- /dev/null +++ b/dhall/Prelude/XML/element.dhall @@ -0,0 +1,59 @@ +{-| +Create an XML element value. + +``` +let XML = ./package.dhall + +in XML.render + ( XML.element + { name = "foo" + , attributes = XML.emptyAttributes + , content = + [ XML.leaf { name = "bar", attributes = [ XML.attribute "n" "1" ] } + , XML.leaf { name = "baz", attributes = [ XML.attribute "n" "2" ] } + ] + } + ) + += "" +``` +-} +let XML = + missing + sha256:ab91a0edaf0513e0083b1dfae5efa160adc99b0e589775a4a699ab77cce528a9 + ? ./Type.dhall + +let List/map = + missing + sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680 + ? ../List/map.dhall + +let Args = + { attributes : List { mapKey : Text, mapValue : Text } + , name : Text + , content : List XML + } + : Type + +let element + : Args → XML + = λ(elem : Args) → + λ(XML : Type) → + λ ( xml + : { text : Text → XML + , rawText : Text → XML + , element : + { attributes : List { mapKey : Text, mapValue : Text } + , content : List XML + , name : Text + } → + XML + } + ) → + xml.element + { attributes = elem.attributes + , name = elem.name + , content = List/map XML@1 XML (λ(x : XML@1) → x XML xml) elem.content + } + +in element diff --git a/dhall/Prelude/XML/emptyAttributes b/dhall/Prelude/XML/emptyAttributes new file mode 100644 index 0000000..9d2d40f --- /dev/null +++ b/dhall/Prelude/XML/emptyAttributes @@ -0,0 +1,3 @@ + missing + sha256:11b86e2d3f3c75d47a1d580213d2a03fd2c36d64f3e9b6381de0ba23472f64d5 +? ./emptyAttributes.dhall diff --git a/dhall/Prelude/XML/emptyAttributes.dhall b/dhall/Prelude/XML/emptyAttributes.dhall new file mode 100644 index 0000000..3a449ba --- /dev/null +++ b/dhall/Prelude/XML/emptyAttributes.dhall @@ -0,0 +1,2 @@ +--| Create an empty XML attribute List. +[] : List { mapKey : Text, mapValue : Text } diff --git a/dhall/Prelude/XML/leaf b/dhall/Prelude/XML/leaf new file mode 100644 index 0000000..47c33b3 --- /dev/null +++ b/dhall/Prelude/XML/leaf @@ -0,0 +1,3 @@ + missing + sha256:5dcedf79a3664a362479f470220bb2f4932facde657c285fd8a3c24ab137c506 +? ./leaf.dhall diff --git a/dhall/Prelude/XML/leaf.dhall b/dhall/Prelude/XML/leaf.dhall new file mode 100644 index 0000000..dba9f91 --- /dev/null +++ b/dhall/Prelude/XML/leaf.dhall @@ -0,0 +1,30 @@ +{-| +Create an XML element value without child elements. + +``` +let XML = ./package.dhall + +in XML.render (XML.leaf { name = "foobar", attributes = XML.emptyAttributes }) + += "" +``` +-} +let XML = + missing + sha256:ab91a0edaf0513e0083b1dfae5efa160adc99b0e589775a4a699ab77cce528a9 + ? ./Type.dhall + +let element = + missing + sha256:79266d604e147caf37e985581523b684f7bac66de0c93dd828841df3dfc445f9 + ? ./element.dhall + +let leaf + : { attributes : List { mapKey : Text, mapValue : Text }, name : Text } → + XML + = λ ( elem + : { attributes : List { mapKey : Text, mapValue : Text }, name : Text } + ) → + element (elem ⫽ { content = [] : List XML }) + +in leaf diff --git a/dhall/Prelude/XML/package.dhall b/dhall/Prelude/XML/package.dhall new file mode 100644 index 0000000..cd3c57f --- /dev/null +++ b/dhall/Prelude/XML/package.dhall @@ -0,0 +1,33 @@ +{ Type = + missing + sha256:ab91a0edaf0513e0083b1dfae5efa160adc99b0e589775a4a699ab77cce528a9 + ? ./Type.dhall +, attribute = + missing + sha256:f7b6c802ca5764d03d5e9a6e48d9cb167c01392f775d9c2c87b83cdaa60ea0cc + ? ./attribute.dhall +, render = + missing + sha256:395c293702c85d99f6f2b461f3eee320f9fe5749c320c2e8b9ea799a7d210b66 + ? ./render.dhall +, element = + missing + sha256:79266d604e147caf37e985581523b684f7bac66de0c93dd828841df3dfc445f9 + ? ./element.dhall +, leaf = + missing + sha256:5dcedf79a3664a362479f470220bb2f4932facde657c285fd8a3c24ab137c506 + ? ./leaf.dhall +, text = + missing + sha256:a59670560a08bfc815893dee1f3eae21a5252400f8a619d1cd7bdd9f48eea2ab + ? ./text.dhall +, rawText = + missing + sha256:2af9d72c151677d4110039e361b7e9faaf2947e6c9d29aa72aea351ad797e05d + ? ./rawText.dhall +, emptyAttributes = + missing + sha256:11b86e2d3f3c75d47a1d580213d2a03fd2c36d64f3e9b6381de0ba23472f64d5 + ? ./emptyAttributes.dhall +} diff --git a/dhall/Prelude/XML/rawText.dhall b/dhall/Prelude/XML/rawText.dhall new file mode 100644 index 0000000..47daf08 --- /dev/null +++ b/dhall/Prelude/XML/rawText.dhall @@ -0,0 +1,40 @@ +{-| +Create a Text value to be inserted into an XML element as content with no +character escaping. + +``` +let XML = ./package.dhall + +in XML.render + ( XML.element + { name = "location" + , attributes = XML.emptyAttributes + , content = [ XML.rawText "" ] + } + ) += "" +``` +-} +let XML = + missing + sha256:ab91a0edaf0513e0083b1dfae5efa160adc99b0e589775a4a699ab77cce528a9 + ? ./Type.dhall + +let rawText + : Text → XML + = λ(d : Text) → + λ(XML : Type) → + λ ( xml + : { text : Text → XML + , rawText : Text → XML + , element : + { attributes : List { mapKey : Text, mapValue : Text } + , content : List XML + , name : Text + } → + XML + } + ) → + xml.rawText d + +in rawText diff --git a/dhall/Prelude/XML/render b/dhall/Prelude/XML/render new file mode 100644 index 0000000..cc509d9 --- /dev/null +++ b/dhall/Prelude/XML/render @@ -0,0 +1,3 @@ + missing + sha256:395c293702c85d99f6f2b461f3eee320f9fe5749c320c2e8b9ea799a7d210b66 +? ./render.dhall diff --git a/dhall/Prelude/XML/render.dhall b/dhall/Prelude/XML/render.dhall new file mode 100644 index 0000000..166c65c --- /dev/null +++ b/dhall/Prelude/XML/render.dhall @@ -0,0 +1,140 @@ +{-| +Render an `XML` value as `Text` + +For indentation and schema validation, see the `xmllint` utility +bundled with libxml2. + +``` +let XML = ./package.dhall + +in XML.render + ( XML.element + { name = "foo" + , attributes = [ XML.attribute "a" "x", XML.attribute "b" (Natural/show 2) ] + , content = [ XML.leaf { name = "bar", attributes = XML.emptyAttributes } ] + } + ) += "" +``` + +-} +let XML = + missing + sha256:ab91a0edaf0513e0083b1dfae5efa160adc99b0e589775a4a699ab77cce528a9 + ? ./Type.dhall + +let Text/concatMap = + missing + sha256:7a0b0b99643de69d6f94ba49441cd0fa0507cbdfa8ace0295f16097af37e226f + ? ../Text/concatMap.dhall + +let Text/concat = + missing + sha256:731265b0288e8a905ecff95c97333ee2db614c39d69f1514cb8eed9259745fc0 + ? ../Text/concat.dhall + +let element = + missing + sha256:79266d604e147caf37e985581523b684f7bac66de0c93dd828841df3dfc445f9 + ? ./element.dhall + +let text = + missing + sha256:a59670560a08bfc815893dee1f3eae21a5252400f8a619d1cd7bdd9f48eea2ab + ? ./text.dhall + +let emptyAttributes = + missing + sha256:11b86e2d3f3c75d47a1d580213d2a03fd2c36d64f3e9b6381de0ba23472f64d5 + ? ./emptyAttributes.dhall + +let Attr = { mapKey : Text, mapValue : Text } + +let esc = λ(x : Text) → λ(y : Text) → Text/replace x "&${y};" + +let `escape&` = esc "&" "amp" + +let `escape<` = esc "<" "lt" + +let `escape>` = esc ">" "gt" + +let `escape'` = esc "'" "apos" + +let `escape"` = esc "\"" "quot" + +let escapeCommon = λ(text : Text) → `escape<` (`escape&` text) + +let escapeAttr = λ(text : Text) → `escape"` (`escape'` (escapeCommon text)) + +let escapeText = λ(text : Text) → `escape>` (escapeCommon text) + +let renderAttr = λ(x : Attr) → " ${x.mapKey}=\"${escapeAttr x.mapValue}\"" + +let render + : XML → Text + = λ(x : XML) → + x + Text + { text = escapeText + , rawText = λ(t : Text) → t + , element = + λ ( elem + : { attributes : List { mapKey : Text, mapValue : Text } + , content : List Text + , name : Text + } + ) → + let attribs = Text/concatMap Attr renderAttr elem.attributes + + in "<${elem.name}${attribs}" + ++ ( if Natural/isZero (List/length Text elem.content) + then "/>" + else ">${Text/concat elem.content}" + ) + } + +let simple = + λ(name : Text) → + λ(content : List XML) → + element { name, attributes = emptyAttributes, content } + +let example0 = + assert + : render + ( simple + "note" + [ simple "to" [ text "Tove" ] + , simple "from" [ text "Jani" ] + , simple "heading" [ text "Reminder" ] + , simple "body" [ text "Don't forget me this weekend!" ] + ] + ) + ≡ Text/replace + "\n" + "" + '' + + Tove + Jani + Reminder + Don't forget me this weekend! + + '' + +let example1 = + assert + : render + ( element + { name = "escape" + , attributes = toMap { attribute = "<>'\"&" } + , content = [ text "<>'\"&" ] + } + ) + ≡ Text/replace + "\n" + "" + '' + <>'"& + '' + +in render diff --git a/dhall/Prelude/XML/text b/dhall/Prelude/XML/text new file mode 100644 index 0000000..9356c77 --- /dev/null +++ b/dhall/Prelude/XML/text @@ -0,0 +1,3 @@ + missing + sha256:a59670560a08bfc815893dee1f3eae21a5252400f8a619d1cd7bdd9f48eea2ab +? ./text.dhall diff --git a/dhall/Prelude/XML/text.dhall b/dhall/Prelude/XML/text.dhall new file mode 100644 index 0000000..7ffcbe0 --- /dev/null +++ b/dhall/Prelude/XML/text.dhall @@ -0,0 +1,39 @@ +{-| +Create a Text value to be inserted into an XML element as content. + +``` +let XML = ./package.dhall + +in XML.render + ( XML.element + { name = "location" + , attributes = XML.emptyAttributes + , content = [ XML.text "/foo/bar" ] + } + ) += "/foo/bar" +``` +-} +let XML = + missing + sha256:ab91a0edaf0513e0083b1dfae5efa160adc99b0e589775a4a699ab77cce528a9 + ? ./Type.dhall + +let text + : Text → XML + = λ(d : Text) → + λ(XML : Type) → + λ ( xml + : { text : Text → XML + , rawText : Text → XML + , element : + { attributes : List { mapKey : Text, mapValue : Text } + , content : List XML + , name : Text + } → + XML + } + ) → + xml.text d + +in text diff --git a/dhall/Prelude/package.dhall b/dhall/Prelude/package.dhall new file mode 100644 index 0000000..5b29800 --- /dev/null +++ b/dhall/Prelude/package.dhall @@ -0,0 +1,73 @@ +{ Bool = + missing + sha256:dde2b9b71afdd26878c06e90cd2cde4488063457d5fbe30e02baed3bec5eede6 + ? ./Bool/package.dhall +, Date = + missing + sha256:fc0c5efc924fa99aa8e5dea5d78c3dc1a24cb550028342b90149ea78cb5ca873 + ? ./Date/package.dhall +, Double = + missing + sha256:b8d20ab3216083622ae371fb42a6732bc67bb2d66e84989c8ddba7556a336cf7 + ? ./Double/package.dhall +, Function = + missing + sha256:6d17cf0fd4fabe1737fb117f87c04b8ff82b299915a5b673c0a543b134b8fffe + ? ./Function/package.dhall +, Integer = + missing + sha256:d1a572ca3a764781496847e4921d7d9a881c18ffcfac6ae28d0e5299066938a0 + ? ./Integer/package.dhall +, JSON = + missing + sha256:5f98b7722fd13509ef448b075e02b9ff98312ae7a406cf53ed25012dbc9990ac + ? ./JSON/package.dhall +, List = + missing + sha256:26d1b4cd800219d8b67043c638926aa6e5517ea74a0bd3e371974514621bca04 + ? ./List/package.dhall +, Location = + missing + sha256:0eb4e4a60814018009c720f6820aaa13cf9491eb1b09afb7b832039c6ee4d470 + ? ./Location/package.dhall +, Map = + missing + sha256:c5e79a9de642644a09b96a2ec3147c5d8662b7926f09610e751c0c0f6ed0b30a + ? ./Map/package.dhall +, Monoid = + missing + sha256:26fafa098600ef7a54ef9dba5ada416bbbdd21df1af306c052420c61553ad4af + ? ./Monoid.dhall +, Natural = + missing + sha256:ee9ed2b28a417ed4e9a0c284801b928bf91b3fbdc1a68616347678c1821f1ddf + ? ./Natural/package.dhall +, NonEmpty = + missing + sha256:c24686a230a4b3cd51e5a57cd4510b4f8242f813d7823d41bac5954e7af56f7a + ? ./NonEmpty/package.dhall +, Operator = + missing + sha256:861f724704a7b4755c96f173e54d03f314492a2d046723404c31ff612b7bf2e6 + ? ./Operator/package.dhall +, Optional = + missing + sha256:74331dfe59c09db65edc7ec4498bff92473c8c06d92752f9470d26e25f91320c + ? ./Optional/package.dhall +, Text = + missing + sha256:79b671a70ac459b799a53bbb8a383cc8b81b40421745c54bf0fb1143168cbd6f + ? ./Text/package.dhall +, Time = + missing + sha256:6715c4c71a113429fef8b94e4561a93c288942dad9dfd75ac545de96c5b5652a + ? ./Time/package.dhall +, TimeZone = + missing + sha256:c17fd403c637856f34c8287168b92974e8c1a3a7331967f75276d179057084fd + ? ./TimeZone/package.dhall +, XML = + missing + sha256:2e111f0952087d42072b059f0bf4c95861a46bffa67ad4c8c39086edf405f32e + ? ./XML/package.dhall +} diff --git a/dhall/asterisk.dhall b/dhall/asterisk.dhall index 8571bbe..f33bd0e 100644 --- a/dhall/asterisk.dhall +++ b/dhall/asterisk.dhall @@ -1,4 +1,4 @@ -let Text/concatMapSep = https://prelude.dhall-lang.org/Text/concatMapSep +let Text/concatMapSep = ./Prelude/Text/concatMapSep let Mailbox = { Type = { id : Text, context : Text, name : Text, email : Text }