Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tonymorris committed Sep 10, 2013
1 parent 5d85a1b commit e3e3dc1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ module Core(
, getChar
, concatMap
, length
, product
, replicate
, foldr
, (++)
Expand Down Expand Up @@ -86,7 +85,6 @@ import Prelude(
, getChar
, concatMap
, length
, product
, replicate
, foldr
, (++)
Expand Down
6 changes: 3 additions & 3 deletions src/Monad/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ apply =
-- >>> lift2 (+) Empty (Full 8)
-- Empty
--
-- >>> lift2 (+) length sum [4,5,6]
-- >>> lift2 (+) len sum (listh [4,5,6])
-- 18
lift2 ::
Monad m =>
Expand Down Expand Up @@ -222,7 +222,7 @@ lift2 =
-- >>> lift3 (\a b c -> a + b + c) Empty Empty (Full 9)
-- Empty
--
-- >>> lift3 (\a b c -> a + b + c) length sum product [4,5,6]
-- >>> lift3 (\a b c -> a + b + c) len sum product (listh [4,5,6])
-- 138
lift3 ::
Monad m =>
Expand Down Expand Up @@ -258,7 +258,7 @@ lift3 =
-- >>> lift4 (\a b c d -> a + b + c + d) Empty Empty (Full 9) (Full 10)
-- Empty
--
-- >>> lift4 (\a b c d -> a + b + c + d) length sum product (sum . filter even) [4,5,6]
-- >>> lift4 (\a b c d -> a + b + c + d) len sum product (sum . filter even) (listh [4,5,6])
-- 148
lift4 ::
Monad m =>
Expand Down
16 changes: 16 additions & 0 deletions src/Structure/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ headOr ::
headOr =
error "todo"

-- | The product of the elements of a list.
--
-- >>> product (1 :. 2 :. 3 :. Nil)
-- 6
--
-- >>> product (1 :. 2 :. 3 :. 4 :. Nil)
-- 24
product ::
List Int
-> Int
product =
foldLeft (*) 1

-- Exercise 2
-- Relative Difficulty: 2
-- Correctness: 2.5 marks
Expand All @@ -79,6 +92,9 @@ headOr =
-- >>> sum (1 :. 2 :. 3 :. Nil)
-- 6
--
-- >>> sum (1 :. 2 :. 3 :. 4 :. Nil)
-- 10
--
-- prop> foldLeft (-) (sum x) x == 0
sum ::
List Int
Expand Down

0 comments on commit e3e3dc1

Please sign in to comment.