Set 3a, Set 3b: clarifications

thanks to Olli Hemminki
This commit is contained in:
Joel Kaasinen
2020-05-18 09:38:37 +03:00
parent 829a43d3c5
commit 3019ce13f3
2 changed files with 14 additions and 10 deletions
+9 -8
View File
@@ -113,14 +113,15 @@ capitalize = todo
-- * the function takeWhile
powers :: Int -> Int -> [Int]
powers n max = todo
powers k max = todo
------------------------------------------------------------------------------
-- Ex 7: implement a functional while loop. That is, a function while
-- that that takes an updating function, a checking function and an
-- Ex 7: implement a functional while loop. While should be a function
-- that that takes a checking function, an updating function, and an
-- initial value. While should repeatedly apply the updating function
-- to the initial value as long as the value passes the checking function.
-- Finally, the value that doesn't pass the check is returned.
-- to the initial value as long as the value passes the checking
-- function. Finally, the value that doesn't pass the check is
-- returned.
--
-- Examples:
--
@@ -142,14 +143,14 @@ while check update initial = todo
-- function returns an Either value. A Left value means stop, a Right
-- value means keep looping.
--
-- The call `whileEither check x` should call `check x`, and if the
-- The call `whileRight check x` should call `check x`, and if the
-- result is a Left, return the contents of the Left. If the result is
-- a Right, the function should call `check` on the contents of the
-- Right and so on.
--
-- Examples (see definition of step below):
-- whileEither (step 100) 1 ==> 128
-- whileEither (step 1000) 3 ==> 1536
-- whileRight (step 100) 1 ==> 128
-- whileRight (step 1000) 3 ==> 1536
whileRight :: (a -> Either b a) -> a -> b
whileRight f x = todo
+5 -2
View File
@@ -13,9 +13,12 @@
-- * map
-- * filter
-- * concat
-- * (!!)
--
-- The (:) operator is available, as is list literal syntax [a,b,c].
--
-- Feel free to use if-then-else, guards, and ordering functions (< and > etc.).
--
-- The tests will check that you haven't added imports :)
{-# LANGUAGE NoImplicitPrelude #-}
@@ -88,7 +91,7 @@ indexDefault xs i def = todo
-- Ex 5: define a function that checks if the given list is in
-- increasing order.
--
-- Use only pattern matching and recursion.
-- Use pattern matching and recursion to iterate through the list.
sorted :: [Int] -> Bool
sorted xs = todo
@@ -159,7 +162,7 @@ map2 f as bs = todo
-- maybeMap is given a list ([a]) and a function of type a -> Maybe b.
-- This function is called for all values in the list. If the function
-- returns Just x, x will be in the result list. If the function
-- returns Nothing, nothing gets added to the result list.
-- returns Nothing, no value gets added to the result list.
--
-- Examples:
--