toMap normalization: Misc improvements (#1116)

…addressing my own comments on
https://github.com/dhall-lang/dhall-haskell/pull/1041.
This commit is contained in:
Simon Jakobi 2019-07-15 23:50:40 +02:00 committed by GitHub
parent 3856612763
commit e044b4ab68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 15 deletions

View File

@ -1668,17 +1668,15 @@ normalizeWithM ctx e0 = loop (denote e0)
t' <- traverse loop t
case x' of
RecordLit kvsX -> do
let entry key value =
Data.Sequence.singleton
(RecordLit
(Dhall.Map.fromList
[ ("mapKey" , TextLit (Chunks [] key))
, ("mapValue", value )
]
)
let entry (key, value) =
RecordLit
(Dhall.Map.fromList
[ ("mapKey" , TextLit (Chunks [] key))
, ("mapValue", value )
]
)
let keyValues = Dhall.Map.foldMapWithKey entry kvsX
let keyValues = Data.Sequence.fromList (map entry (Dhall.Map.toList kvsX))
let listType = case t' of
Just (App List itemType) | null keyValues ->

View File

@ -530,13 +530,14 @@ eval !env t =
(x, y, ma) -> VMerge x y ma
ToMap x ma -> case (evalE x, evalE <$> ma) of
(VRecordLit m, Just (VList t)) | null m ->
VListLit (Just t) (Dhall.Map.foldMapWithKey entry m)
(VRecordLit m, _) ->
VListLit Nothing (Dhall.Map.foldMapWithKey entry m)
VListLit (Just t) (Data.Sequence.empty)
(VRecordLit m, _) -> let
entry (k, v) =
VRecordLit (Dhall.Map.fromList [("mapKey", VTextLit $ VChunks [] k),
("mapValue", v)])
s = (Data.Sequence.fromList . map entry . Dhall.Map.toList) m
in VListLit Nothing s
(x, ma) -> VToMap x ma
where
entry key value = Data.Sequence.singleton (VRecordLit (Dhall.Map.fromList [("mapKey", VTextLit $ VChunks [] key),
("mapValue", value)]))
Field t k -> case evalE t of
VRecordLit m
| Just v <- Dhall.Map.lookup k m -> v