Skip to content

Commit a56de2d

Browse files
authored
Merge pull request #5677 from unisonweb/cp/fix-multimap
Fix Multimap.fromList
2 parents 8334f2c + 28ee213 commit a56de2d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

unison-runtime/src/Unison/Runtime/Foreign/Function.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,9 @@ foreignCallHelper = \case
901901
List_sort -> mkForeign $ \(l :: Seq Val) -> pure $ Sq.unstableSort l
902902
Multimap_fromList -> mkForeign $ \(l :: [(Val, Val)]) -> do
903903
let listVals = l <&> \(k, v) -> (k, Sq.singleton v)
904-
evaluate $ Map.fromListWith (<>) listVals
904+
-- Haskell Map.fromList calls the semigroup in reverse order, so we correct for it by flipping.
905+
let result :: Map Val Val = fmap encodeVal $ Map.fromListWith (flip (<>)) listVals
906+
evaluate result
905907
Set_fromList -> mkForeign $ \(l :: [Val]) -> do
906908
m <- evaluate $ Map.fromList $ zip l (repeat unitValue)
907909
pure . Data1 Ty.setRef TT.setWrapTag $ encodeVal m

0 commit comments

Comments
 (0)