Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hashable-related test failures #2152

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dhall-json/src/Dhall/JSONToDhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,8 @@ dhallFromJSON (Conversion {..}) expressionType =
, ("mapValue", val)
]

let records = (fmap f . Seq.fromList . HM.toList) keyExprMap
let records =
(fmap f . Seq.fromList . List.sort . HM.toList) keyExprMap

let typeAnn = if HM.null o then Just t else Nothing

Expand Down
20 changes: 7 additions & 13 deletions dhall/src/Dhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ import qualified Data.Functor.Compose
import qualified Data.Functor.Product
import qualified Data.HashMap.Strict as HashMap
import qualified Data.HashSet
import qualified Data.List
import qualified Data.List as List
import qualified Data.List.NonEmpty
import qualified Data.Map
import qualified Data.Maybe
Expand Down Expand Up @@ -1183,7 +1183,7 @@ setHelper size toSet (Decoder extractIn expectedIn) = Decoder extractOut expecte
vList = Data.Foldable.toList vSeq
vSet = toSet vList
sameSize = size vSet == Data.Sequence.length vSeq
duplicates = vList Data.List.\\ Data.Foldable.toList vSet
duplicates = vList List.\\ Data.Foldable.toList vSet
err | length duplicates == 1 =
"One duplicate element in the list: "
<> (Data.Text.pack $ show $ head duplicates)
Expand Down Expand Up @@ -1216,10 +1216,10 @@ map k v = fmap Data.Map.fromList (list (pairFromMapEntry k v))

{-| Decode a `HashMap` from a @toMap@ expression or generally a @Prelude.Map.Type@

>>> input (Dhall.hashMap strictText bool) "toMap { a = True, b = False }"
fromList [("a",True),("b",False)]
>>> input (Dhall.hashMap strictText bool) "[ { mapKey = \"foo\", mapValue = True } ]"
fromList [("foo",True)]
>>> fmap (List.sort . HashMap.toList) (input (Dhall.hashMap strictText bool) "toMap { a = True, b = False }")
[("a",True),("b",False)]
>>> fmap (List.sort . HashMap.toList) (input (Dhall.hashMap strictText bool) "[ { mapKey = \"foo\", mapValue = True } ]")
[("foo",True)]

If there are duplicate @mapKey@s, later @mapValue@s take precedence:

Expand Down Expand Up @@ -2198,13 +2198,7 @@ instance ToDhall a => ToDhall (Vector a) where
instance ToDhall a => ToDhall (Data.Set.Set a) where
injectWith = fmap (contramap Data.Set.toAscList) injectWith

{-| Note that the output list may not be sorted

>>> let x = Data.HashSet.fromList ["hi", "mom" :: Text]
>>> prettyExpr $ embed inject x
[ "mom", "hi" ]

-}
-- | Note that the output list may not be sorted
instance ToDhall a => ToDhall (Data.HashSet.HashSet a) where
injectWith = fmap (contramap Data.HashSet.toList) injectWith

Expand Down