Monday, January 2, 2012

[IFP] Exercises 1.4

I feel like I understand currying and function application, but I'm still really, really, having a difficult time with this type declaration business.

1.4.1 Define one appropriate type for the definite integral function of mathematical analysis, as in used in the phrase 'the integral of f from a to b'.
integral :: (num -> num) -> num -> num -> num

1.4.2 Give examples of functions with these types....

multiply :: num -> (num -> num)
multiply a b = a * b

applyFToThree :: (num -> num) -> num
applyFToThree f = f 3

theSame :: (num -> num) -> (num -> num)
theSame f = g
    where g x = f x 

1.4.3 Give a definition of a function sign :: num -> num which returns 1 if its argument is positive, -1 if its argument is negative, and 0 otherwise.
sign :: num -> num
sign x =  1, if x > 0
       = -1, if x < 0
       =  0, otherwise

1.4.4 Suggest possible types for these functions: one x = 1, apply f x = f x, compose f g x = f (g x)
one :: α -> num
apply :: (num -> num) -> num -> num
compose :: (num -> num) -> (num -> num) -> num -> num

No comments:

Post a Comment