mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
Set 3a, Set 3b: clarifications
thanks to Olli Hemminki
This commit is contained in:
+9
-8
@@ -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
@@ -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:
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user