-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a test that will fail given a strict implementation of accumulate
- Loading branch information
Showing
2 changed files
with
16 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
module Accumulate (accumulate) where | ||
|
||
accumulate :: (a -> b) -> [a] -> [b] | ||
accumulate = map | ||
{- | ||
accumulate _ [] = [] | ||
accumulate f (x:xs) = f x : accumulate f xs | ||
|
||
-- Some other definitions that are easily possible: | ||
{- | ||
accumulate = fmap | ||
-- Some other reasonable definitions: | ||
accumulate f = foldr ((:) . f) [] | ||
accumulate f xs = [f x | x <- xs] | ||
accumulate f (x:xs) = f x : accumulate xs | ||
accumulate _ [] = [] | ||
-- Commonly submitted inefficient solution (we test for this now): | ||
accumulate f xs = accumulate' [] | ||
where | ||
accumulate' acc [] = acc | ||
accumulate' acc (x:xs) = accumulate' (f x : acc) xs | ||
-} |