toMap normalization: Misc improvements (#1116)
…addressing my own comments on https://github.com/dhall-lang/dhall-haskell/pull/1041.
This commit is contained in:
parent
3856612763
commit
e044b4ab68
|
@ -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 ->
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user