Skip to content

Commit f49e273

Browse files
authored
Remove Optional/fold and Optional/build (#1802)
…as standardized in dhall-lang/dhall-lang#1014.
1 parent ab665c2 commit f49e273

File tree

22 files changed

+13
-294
lines changed

22 files changed

+13
-294
lines changed

dhall-bash/src/Dhall/Bash.hs

-2
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ dhallToStatement expr0 var0 = go (Dhall.Core.normalize expr0)
321321
go e@(ListReverse ) = Left (UnsupportedStatement e)
322322
go e@(Optional ) = Left (UnsupportedStatement e)
323323
go e@(None ) = Left (UnsupportedStatement e)
324-
go e@(OptionalFold ) = Left (UnsupportedStatement e)
325-
go e@(OptionalBuild ) = Left (UnsupportedStatement e)
326324
go e@(Record {}) = Left (UnsupportedStatement e)
327325
go e@(Union {}) = Left (UnsupportedStatement e)
328326
go e@(Combine {}) = Left (UnsupportedStatement e)

dhall-json/src/Dhall/JSON.hs

-6
Original file line numberDiff line numberDiff line change
@@ -963,12 +963,6 @@ convertToHomogeneousMaps (Conversion {..}) e0 = loop (Core.normalize e0)
963963
Core.None ->
964964
Core.None
965965

966-
Core.OptionalFold ->
967-
Core.OptionalFold
968-
969-
Core.OptionalBuild ->
970-
Core.OptionalBuild
971-
972966
Core.Record a ->
973967
Core.Record a'
974968
where

dhall-nix/release.nix

-19
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,6 @@ in
8181
then (Some 0)
8282
else (None Natural)
8383
'';
84-
testOptionalFold = dhallToNix ''
85-
Optional/fold
86-
Natural
87-
(Some 1)
88-
Natural
89-
'';
90-
testOptionalBuild = dhallToNix ''
91-
λ(b : Bool)
92-
→ Optional/build
93-
Natural
94-
( λ(optional : Type)
95-
→ λ(just : Natural → optional)
96-
→ λ(nothing : optional)
97-
→ if b then just 1 else nothing
98-
)
99-
'';
10084
testNone = dhallToNix "None Natural";
10185
testSome = dhallToNix "Some 4";
10286
testRecord = dhallToNix "{}";
@@ -182,9 +166,6 @@ in
182166
assert (testOptional {} == {});
183167
assert (testOptionalLit true == 0);
184168
assert (testOptionalLit false == null);
185-
assert (testOptionalFold (n : n) 0 == 1);
186-
assert (testOptionalBuild true == 1);
187-
assert (testOptionalBuild false == null);
188169
assert (testRecord == {});
189170
assert (testRecordLit == { foo = 1; bar = true; });
190171
assert (testUnion == {});

dhall-nix/src/Dhall/Nix.hs

-14
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ import Data.Void (Void, absurd)
101101
import Dhall.Core
102102
( Binding(..)
103103
, Chunks(..)
104-
, Const(..)
105104
, DhallDouble(..)
106105
, Expr(..)
107106
, MultiLet(..)
@@ -524,19 +523,6 @@ dhallToNix e =
524523
loop Optional = return (Fix (NAbs "t" untranslatable))
525524
loop (Some a) = loop a
526525
loop None = return (Fix (NConstant NNull))
527-
loop OptionalFold = do
528-
let e0 = Fix (NBinary NEq "x" (Fix (NConstant NNull)))
529-
let e1 = Fix (NIf e0 "nothing" (Fix (NBinary NApp "just" "x")))
530-
let e2 = Fix (NAbs "t" (Fix (NAbs "just" (Fix (NAbs "nothing" e1)))))
531-
return (Fix (NAbs "t" (Fix (NAbs "x" e2))))
532-
loop OptionalBuild = do
533-
let e0 = Pi "nothing" "optional" "optional"
534-
let e1 = Pi "just" (Pi "_" "a" "optional") e0
535-
let e2 = Pi "optional" (Const Type) e1
536-
let e3 = App None "a"
537-
let e4 = Lam "x" "a" (Some "x")
538-
let e5 = App (App (App "f" (App Optional "a")) e4) e3
539-
loop (Lam "a" (Const Type) (Lam "f" e2 e5))
540526
loop (Record _) = return untranslatable
541527
loop (RecordLit a) = do
542528
a' <- traverse loop a

dhall/benchmark/examples/issue108.dhall

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ Text , user : Optional Text } xs Text ( λ ( x : { cores : Natural , host : Text
1515
{} | MIPS64el_Linux : {} | PowerPC_Linux : {} | X86_64_Cygwin : {} |
1616
X86_64_Darwin : {} | X86_64_FreeBSD : {} | X86_64_Linux : {} | X86_64_Solaris :
1717
{} > , speedFactor : Natural , supportedFeatures : List Text , user : Optional
18-
Text } ) λ(y : Text) Optional/fold Text x.user Text (λ(user : Text) user
19-
++ "@" ++ x.host ++ "") x.host ++ " " ++ ( merge { Empty = λ(_ : {}) "",
18+
Text } ) λ(y : Text)
19+
merge { None = x.host, Some = λ(user : Text) "${user}@${x.host}" } x.user
20+
++ " " ++ ( merge { Empty = λ(_ : {}) "",
2021
NonEmpty = λ(result : Text) result } ( List/fold < AArch64_Linux : {} |
2122
ARMv5tel_Linux : {} | ARMv7l_Linux : {} | I686_Cygwin : {} | I686_Linux : {} |
2223
MIPS64el_Linux : {} | PowerPC_Linux : {} | X86_64_Cygwin : {} | X86_64_Darwin :
-21 Bytes
Binary file not shown.
-110 Bytes
Binary file not shown.

dhall/dhall-lang

Submodule dhall-lang updated 55 files

dhall/dhall.cabal

+2-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ Extra-Source-Files:
189189
dhall-lang/tests/binary-decode/success/unit/*.dhallb
190190
dhall-lang/tests/binary-decode/success/unit/imports/*.dhall
191191
dhall-lang/tests/binary-decode/success/unit/imports/*.dhallb
192-
dhall-lang/tests/import/cache/dhall/1220efc43103e49b56c5bf089db8e0365bbfc455b8a2f0dc6ee5727a3586f85969fd
192+
dhall-lang/tests/import/cache/dhall/12203871180b87ecaba8b53fffb2a8b52d3fce98098fab09a6f759358b9e8042eedc
193+
dhall-lang/tests/import/cache/dhall/1220618f785ce8f3930a9144398f576f0a992544b51212bc9108c31b4e670dc6ed21
193194
dhall-lang/tests/import/data/*.dhall
194195
dhall-lang/tests/import/data/*.txt
195196
dhall-lang/tests/import/failure/*.dhall

dhall/src/Dhall/Binary.hs

-8
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,8 @@ decodeExpressionInternal decodeEmbed = go
190190
| sb == "Natural/show" -> return NaturalShow
191191
13 | sb == "Integer/clamp" -> return IntegerClamp
192192
| sb == "Natural/build" -> return NaturalBuild
193-
| sb == "Optional/fold" -> return OptionalFold
194193
14 | sb == "Integer/negate" -> return IntegerNegate
195194
| sb == "Natural/isZero" -> return NaturalIsZero
196-
| sb == "Optional/build" -> return OptionalBuild
197195
16 | sb == "Integer/toDouble" -> return IntegerToDouble
198196
| sb == "Natural/subtract" -> return NaturalSubtract
199197
17 | sb == "Natural/toInteger" -> return NaturalToInteger
@@ -662,12 +660,6 @@ encodeExpressionInternal encodeEmbed = go
662660
ListReverse ->
663661
Encoding.encodeUtf8ByteArray "List/reverse"
664662

665-
OptionalFold ->
666-
Encoding.encodeUtf8ByteArray "Optional/fold"
667-
668-
OptionalBuild ->
669-
Encoding.encodeUtf8ByteArray "Optional/build"
670-
671663
Bool ->
672664
Encoding.encodeUtf8ByteArray "Bool"
673665

dhall/src/Dhall/Diff.hs

-12
Original file line numberDiff line numberDiff line change
@@ -1272,18 +1272,6 @@ diffPrimitiveExpression l@None r =
12721272
mismatch l r
12731273
diffPrimitiveExpression l r@None =
12741274
mismatch l r
1275-
diffPrimitiveExpression OptionalFold OptionalFold =
1276-
""
1277-
diffPrimitiveExpression l@OptionalFold r =
1278-
mismatch l r
1279-
diffPrimitiveExpression l r@OptionalFold =
1280-
mismatch l r
1281-
diffPrimitiveExpression OptionalBuild OptionalBuild =
1282-
""
1283-
diffPrimitiveExpression l@OptionalBuild r =
1284-
mismatch l r
1285-
diffPrimitiveExpression l r@OptionalBuild =
1286-
mismatch l r
12871275
diffPrimitiveExpression (BoolLit aL) (BoolLit aR) =
12881276
diffBool aL aR
12891277
diffPrimitiveExpression l@(BoolLit {}) r =

dhall/src/Dhall/Eval.hs

-40
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ data Val a
211211
| VOptional (Val a)
212212
| VSome (Val a)
213213
| VNone (Val a)
214-
| VOptionalFold (Val a) !(Val a) (Val a) !(Val a) !(Val a)
215-
| VOptionalBuild (Val a) !(Val a)
216214
| VRecord !(Map Text (Val a))
217215
| VRecordLit !(Map Text (Val a))
218216
| VUnion !(Map Text (Maybe (Val a)))
@@ -671,32 +669,6 @@ eval !env t0 =
671669
VSome (eval env t)
672670
None ->
673671
VPrim $ \ ~a -> VNone a
674-
OptionalFold ->
675-
VPrim $ \ ~a ->
676-
VPrim $ \case
677-
VNone _ ->
678-
VHLam (Typed "optional" (VConst Type)) $ \optional ->
679-
VHLam (Typed "some" (a ~> optional)) $ \_some ->
680-
VHLam (Typed "none" optional) $ \none ->
681-
none
682-
VSome t ->
683-
VHLam (Typed "optional" (VConst Type)) $ \optional ->
684-
VHLam (Typed "some" (a ~> optional)) $ \some ->
685-
VHLam (Typed "none" optional) $ \_none ->
686-
some `vApp` t
687-
opt ->
688-
VPrim $ \o ->
689-
VPrim $ \s ->
690-
VPrim $ \n ->
691-
VOptionalFold a opt o s n
692-
OptionalBuild ->
693-
VPrim $ \ ~a ->
694-
VPrim $ \case
695-
VPrimVar -> VOptionalBuild a VPrimVar
696-
t -> t
697-
`vApp` VOptional a
698-
`vApp` VHLam (Typed "a" a) VSome
699-
`vApp` VNone a
700672
Record kts ->
701673
VRecord (Map.sort (fmap (eval env) kts))
702674
RecordLit kts ->
@@ -937,8 +909,6 @@ conv !env t0 t0' =
937909
conv env t t'
938910
(VNone _, VNone _) ->
939911
True
940-
(VOptionalBuild _ t, VOptionalBuild _ t') ->
941-
conv env t t'
942912
(VRecord m, VRecord m') ->
943913
eqMapsBy (conv env) m m'
944914
(VRecordLit m, VRecordLit m') ->
@@ -969,8 +939,6 @@ conv !env t0 t0' =
969939
eqMapsBy (eqMaybeBy (conv env)) m m' && k == k' && eqMaybeBy (conv env) mt mt'
970940
(VEmbed a, VEmbed a') ->
971941
a == a'
972-
(VOptionalFold a t _ u v, VOptionalFold a' t' _ u' v') ->
973-
conv env a a' && conv env t t' && conv env u u' && conv env v v'
974942
(_, _) ->
975943
False
976944
where
@@ -1123,10 +1091,6 @@ quote !env !t0 =
11231091
Some (quote env t)
11241092
VNone t ->
11251093
None `qApp` t
1126-
VOptionalFold a o t u v ->
1127-
OptionalFold `qApp` a `qApp` o `qApp` t `qApp` u `qApp` v
1128-
VOptionalBuild a t ->
1129-
OptionalBuild `qApp` a `qApp` t
11301094
VRecord m ->
11311095
Record (fmap (quote env) m)
11321096
VRecordLit m ->
@@ -1303,10 +1267,6 @@ alphaNormalize = goEnv EmptyNames
13031267
Some (go t)
13041268
None ->
13051269
None
1306-
OptionalFold ->
1307-
OptionalFold
1308-
OptionalBuild ->
1309-
OptionalBuild
13101270
Record kts ->
13111271
Record (fmap go kts)
13121272
RecordLit kts ->

dhall/src/Dhall/Lint.hs

+2-72
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ module Dhall.Lint
1414
, fixAssert
1515
, fixParentPath
1616
, removeLetInLet
17-
, replaceOptionalBuildFold
18-
, replaceSaturatedOptionalFold
1917
, useToMap
2018
) where
2119

@@ -24,7 +22,6 @@ import Control.Applicative ((<|>))
2422
import Dhall.Syntax
2523
( Binding(..)
2624
, Chunks(..)
27-
, Const(..)
2825
, Directory(..)
2926
, Expr(..)
3027
, File(..)
@@ -51,20 +48,15 @@ import qualified Lens.Family
5148
* fixes @let a = x ≡ y@ to be @let a = assert : x ≡ y@
5249
* consolidates nested @let@ bindings to use a multiple-@let@ binding with 'removeLetInLet'
5350
* fixes paths of the form @.\/..\/foo@ to @..\/foo@
54-
* Replaces deprecated @Optional\/fold@ and @Optional\/build@ built-ins
5551
-}
5652
lint :: Expr s Import -> Expr s Import
57-
lint = Dhall.Optics.rewriteOf subExpressions lowerPriorityRewrite
58-
. Dhall.Optics.rewriteOf subExpressions higherPriorityRewrite
53+
lint = Dhall.Optics.rewriteOf subExpressions rewrite
5954
where
60-
lowerPriorityRewrite e =
55+
rewrite e =
6156
fixAssert e
6257
<|> removeUnusedBindings e
6358
<|> fixParentPath e
6459
<|> removeLetInLet e
65-
<|> replaceOptionalBuildFold e
66-
67-
higherPriorityRewrite = replaceSaturatedOptionalFold
6860

6961
-- | Remove unused `Let` bindings.
7062
removeUnusedBindings :: Eq a => Expr s a -> Maybe (Expr s a)
@@ -132,68 +124,6 @@ removeLetInLet :: Expr s a -> Maybe (Expr s a)
132124
removeLetInLet (Let binding (Note _ l@Let{})) = Just (Let binding l)
133125
removeLetInLet _ = Nothing
134126

135-
-- | This replaces @Optional/fold@ and @Optional/build@, both of which can be
136-
-- implemented within the language
137-
replaceOptionalBuildFold :: Expr s a -> Maybe (Expr s a)
138-
replaceOptionalBuildFold OptionalBuild =
139-
Just
140-
(Lam "a" (Const Type)
141-
(Lam "build"
142-
(Pi "optional" (Const Type)
143-
(Pi "some" (Pi "_" "a" "optional")
144-
(Pi "none" "optional" "optional")
145-
)
146-
)
147-
(App (App (App "build" (App Optional "a")) (Lam "x" "a" (Some "x"))) (App None "a"))
148-
)
149-
)
150-
replaceOptionalBuildFold OptionalFold =
151-
Just
152-
(Lam "a" (Const Type)
153-
(Lam "o" (App Optional "a")
154-
(Lam "optional" (Const Type)
155-
(Lam "some" (Pi "_" "a" "optional")
156-
(Lam "none" "optional"
157-
(Merge
158-
(RecordLit
159-
[ ("Some", "some")
160-
, ("None", "none")
161-
]
162-
)
163-
"o"
164-
Nothing
165-
)
166-
)
167-
)
168-
)
169-
)
170-
)
171-
replaceOptionalBuildFold _ =
172-
Nothing
173-
174-
-- | This replaces a saturated @Optional/fold@ with the equivalent @merge@
175-
-- expression
176-
replaceSaturatedOptionalFold :: Expr s a -> Maybe (Expr s a)
177-
replaceSaturatedOptionalFold
178-
(App
179-
(Core.shallowDenote -> App
180-
(Core.shallowDenote -> App
181-
(Core.shallowDenote -> App
182-
(Core.shallowDenote -> App
183-
(Core.shallowDenote -> OptionalFold)
184-
_
185-
)
186-
o
187-
)
188-
_
189-
)
190-
some
191-
)
192-
none
193-
) = Just (Merge (RecordLit [ ("Some", some), ("None", none) ]) o Nothing)
194-
replaceSaturatedOptionalFold _ =
195-
Nothing
196-
197127
-- | This replaces a record of key-value pairs with the equivalent use of
198128
-- @toMap@
199129
--

0 commit comments

Comments
 (0)