#Problems
##Day 1
- rest: takes a list and returns all the elements except the first element
- last: takes a list and returns the last element
- count: takes a list and returns length of list
- elemAt: takes a list, an index and returns the element at that position e.g. elemAt 4 [1,2,3,4,5] = 5
- take: takes a list, a number and returns that many elements from the list. e.g. take 3 [1,2,3,4,5] = [1,2,3]ii
- drop: takes a list, a number and returns the list without that many elements from the list. e.g. drop 3 [1,2,3,i4,5] = [4,5]
##Day 2
- Create a function
second
that gives you the second element of a tuple - Create a function
zip
that takes two lists and returns a tuple with elements from both the lists:zip [1,2,3] ['a','b','c'] = [(1,'a'),(2,'b'),(3,'c')]
- Create a function
curry
that takes function of type:(Int,Int) -> Int
and returns a function in curried form:Int -> Int -> Int
. So, if I say callcurry addTuples
, the result should beadd
whereaddTuple = \(a,b) -> a + b
andadd = \a b -> a + b
. - Create a function
uncurry
that does the opposite of above. - Create a function
flip
that flips the arguments. Ifsubtract x y = x - y
, thenflip subtract
should be the equivalent ofsubtract x y = y - x
. - Create a function
subtract
that does subtraction. Subtract 2 from all numbers in a list usingmap
and thesubtract
. First try it using anonymous functions and then try to use theflip
defined above. Return a curried function. - Create a list of functions:
list :: [(Int -> Int)]
. Put whatever functions you need. - Map over the above list so that the resultant list contains all functions that return
double
the value of their counterparts in the earlier list. - Apply composition over all the elements in the above list and return one function.
##Day 6 Implement Cycle Rental: write functions for listing all cycles, renting a cycle, returning a cycle and paying the rental price which is number of days taken for rent times the rent per day of the cycle taken on rent.
##Day 8
- Write an
Identity
typeclass. It should have anident
function that takes a value and gives it back. - Is
Identity
a functor? If yes, create an instance ofFunctor
for it. - Implement
Functor
forBinaryTree
that we wroter earlier. - Write a function
duration
that takes aRental
that we defined in the cycle store problem and returns aMaybe Int
. It should returnNothing
ifendDate
isNothing
else it should return a value. Usefmap
for writing this.