module HW7 where

import Hugs.Prelude

 

-- WEEK 7

 

{-######################################

 QUESTION 10.2

######################################-}

-- Test Functions

 

f::Int->Bool

f n

  | n==0=True

  | otherwise=False

 

 

{- 

  "(id.f) (f.id) id f = f "

 

id is a polymorphic function that returns its argument,

so doing the 3 cases above just execute f

 

-}

 

{-######################################

 QUESTION 10.3

######################################-}

myinc::Int->Int

myinc x=x+1

 

 

composeList::[(a->a)]->(a->a)

composeList []=id

composeList (x:xs)=x. composeList xs

 

{-

 upon testing "composeList" with my function "myinc"

 I obtain the following result:

 

 composeList [(myinc),(myinc),(myinc)] 5 ==>8

 

 the "myinc" function is applied to 5 3 times which

 has the same result as doing  myinc(myinc(myinc 5))=>8

 

 when i use composeList [] 5  i get back 5 because it is the

 empty list case and the function "id" is applied to 5

 

-}

 

{-######################################

 QUESTION 10.7

######################################-}

 

flip::(a->b->c)->(b ->a->c)

flip func =(\x y->func y x)

 

 

{-######################################

 QUESTION 10.8

######################################-}

 

notwhite::Char->Bool

notwhite = \ch->not(elem ch " \t\n")

 

{-######################################

 QUESTION 10.9

######################################-}

 

total::(Int->Int)->(Int->Int)

total func= \n-> sum(map func [0..n])

 

 

{-######################################

 QUESTION 10.10

 

 a very aproximative derivative at x

  slope=f(x+dx)-f(x)/(dx)

  calculate the slope at point x for f

######################################-}

 

slope::(Float->Float)->(Float->Float)

slope func= \n->( (func (n+0.2))- (func n) ) /(0.2)

 

 

{-######################################-}

{-######################################-}