clarify Set3b

This commit is contained in:
Joel Kaasinen
2020-05-11 16:29:42 +03:00
parent 8685c46448
commit 2ac0028961
+15 -1
View File
@@ -6,6 +6,16 @@
-- you'll be working in a limited environment where almost none of the -- you'll be working in a limited environment where almost none of the
-- standard library is available. -- standard library is available.
-- --
-- At least the following standard library functions are missing:
-- * (++)
-- * head
-- * tail
-- * map
-- * filter
-- * concat
--
-- The (:) operator is available, as is list literal syntax [a,b,c].
--
-- The tests will check that you haven't added imports :) -- The tests will check that you haven't added imports :)
{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE NoImplicitPrelude #-}
@@ -55,7 +65,7 @@ mylast def xs = todo
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Ex 4: safe list indexing. Define a function indexDefault so that -- Ex 4: safe list indexing. Define a function indexDefault so that
-- indexDefault xs def i -- indexDefault xs i def
-- gets the element at index i in the list xs. If i is not a valid -- gets the element at index i in the list xs. If i is not a valid
-- index, def is returned. -- index, def is returned.
-- --
@@ -130,8 +140,12 @@ mymaximum bigger initial xs = todo
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Ex 9: define a version of map that takes a two-argument function -- Ex 9: define a version of map that takes a two-argument function
-- and two lists. Example: -- and two lists. Example:
--
-- map2 f [x,y,z,w] [a,b,c] ==> [f x a, f y b, f z c] -- map2 f [x,y,z,w] [a,b,c] ==> [f x a, f y b, f z c]
-- --
-- If the lists have differing lengths, ignore the trailing elements
-- of the longer list.
--
-- Use recursion and pattern matching. Do not use any library functions. -- Use recursion and pattern matching. Do not use any library functions.
map2 :: (a -> b -> c) -> [a] -> [b] -> [c] map2 :: (a -> b -> c) -> [a] -> [b] -> [c]