module HW8 where
import Hugs.Prelude
{-######################################
QUESTION 10.12
BEFORE:
------
comp2::(a->b)->(b->b->c)->(a->a->c)
comp2 f g = (\x y ->g (f x (f y))
total::(Int->Int)->(Int->Int)
total func = \n-> sum(map func [0..n])
######################################-}
comp2 :: (a -> b)
-> (b -> b -> c) -> (a -> aa -> c)
comp2 f = \g x y
-> g (f x) (f y)
total::(Int->Int)->(Int->Int)
total = \func n->
sum (map func [0 .. n])
{-######################################
(filter (>0). map (+1)) [-3,-2,-1,0,1,2,3] gives [1,2,3,4]
(map (+1). filter (> -1)) [-3,-2,-1,0,1,2,3] also
gives [1,2,3,4]
######################################-}
{-
ANSWER
sec1 ==> (+1)
sec2 ==> (> -1)
-}
{-######################################
QUESTION 10.33
f.(g.h) ?= (f.g).h
knowing that
(f.g) x = f (g x)
######################################-}
{-
f.(g.h) x ==> f
((g.h) x) ==> f( g( h x) )
(f.g).h x ==>
(f.g) (h x) ==> f( g( h x) )
-}
{-######################################
QUESTION 10.34
knowing that
(f.g) x = f (g x)
and by the definition
of
id::a->a
id x=x
######################################-}
{-
(id.f) x ==> id (f
x) ==> f x
-}
{-######################################-}
{-######################################-}