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

match Foldable.foldl1's argument order to DA.List.foldl1's order #12685

Merged
merged 1 commit into from
Feb 1, 2022
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
2 changes: 1 addition & 1 deletion compiler/damlc/daml-stdlib-src/DA/Foldable.daml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Foldable t where
foldl1 : (a -> a -> a) -> t a -> a
foldl1 f xs = O.fromSomeNote "foldl1: empty input" (foldl mf None xs)
where
mf m x = Some (case m of None -> x; Some y -> f x y)
mf m x = Some (case m of None -> x; Some y -> f y x)

-- | List of elements of a structure, from left to right.
toList : t a -> [a]
Expand Down
21 changes: 14 additions & 7 deletions compiler/damlc/tests/daml-test-files/List.daml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.

-- @INFO range=127:17-127:32; Use dedup
-- @INFO range=313:10-313:24; Evaluate
-- @INFO range=328:38-328:48; Use sum
-- @INFO range=329:43-329:53; Use sum
-- @INFO range=330:29-330:39; Use sum
-- @INFO range=333:3-333:23; Use head
-- @INFO range=338:29-338:36; Use head
-- @INFO range=128:17-128:32; Use dedup
-- @INFO range=314:10-314:24; Evaluate
-- @INFO range=335:38-335:48; Use sum
-- @INFO range=336:43-336:53; Use sum
-- @INFO range=337:29-337:39; Use sum
-- @INFO range=340:3-340:23; Use head
-- @INFO range=345:29-345:36; Use head

module List where

import DA.List
import DA.Assert
import DA.Optional
import qualified DA.Foldable as Foldable

data Foo = Foo with x : Int; y : Text
deriving (Eq, Show)
Expand Down Expand Up @@ -324,6 +325,12 @@ testFoldr1 = scenario do
"abc" === foldr1 (<>) ["a", "b", "c"]
2 === foldr1 (-) [1, 2, 3]

testFoldable = scenario do
"abc" === Foldable.foldl1 (<>) ["a", "b", "c"]
-4 === Foldable.foldl1 (-) [1, 2, 3]
"abc" === Foldable.foldr1 (<>) ["a", "b", "c"]
2 === Foldable.foldr1 (-) [1, 2, 3]

testRepeatedly = scenario do
[15, 12, 5] === repeatedly (\x -> (foldl1 (+) x, drop 2 x)) [1..5]
[10, 22, 34, 10] === repeatedly (\x -> (foldl1 (+) (take 4 x), drop 3 x)) [1..10]
Expand Down