mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
upto ex. 5
This commit is contained in:
+9
-3
@@ -77,7 +77,9 @@ sums i = sums' i 1
|
||||
-- mylast 0 [1,2,3] ==> 3
|
||||
|
||||
mylast :: a -> [a] -> a
|
||||
mylast def xs = todo
|
||||
mylast def [] = def
|
||||
mylast def [x] = x
|
||||
mylast def (x:xs) = mylast def xs
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Ex 4: safe list indexing. Define a function indexDefault so that
|
||||
@@ -95,7 +97,9 @@ mylast def xs = todo
|
||||
-- indexDefault ["a","b","c"] (-1) "d" ==> "d"
|
||||
|
||||
indexDefault :: [a] -> Int -> a -> a
|
||||
indexDefault xs i def = todo
|
||||
indexDefault [] i def = def
|
||||
indexDefault (x:xs) 0 def = x
|
||||
indexDefault (x:xs) i def = indexDefault xs (i-1) def
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Ex 5: define a function that checks if the given list is in
|
||||
@@ -111,7 +115,8 @@ indexDefault xs i def = todo
|
||||
-- sorted [7,2,7] ==> False
|
||||
|
||||
sorted :: [Int] -> Bool
|
||||
sorted xs = todo
|
||||
sorted (x:y:xs) = (x <= y) && sorted (y:xs)
|
||||
sorted _ = True
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Ex 6: compute the partial sums of the given list like this:
|
||||
@@ -123,6 +128,7 @@ sorted xs = todo
|
||||
-- Use pattern matching and recursion (and the list constructors : and [])
|
||||
|
||||
sumsOf :: [Int] -> [Int]
|
||||
sumsOf [] = []
|
||||
sumsOf xs = todo
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user