
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

HW 10 Prof. Caldwell Due: 5 October 2008 COSC 3015
Exercise 1.1. Based on the code provided on the HW web-page you must write the following functions.
update :: Eq a => (a,b) -> FinFun a b -> FinFun a b functional :: Eq a => [(a,b)] -> Bool domain :: (Eq a, Eq b) => FinFun a b -> [a] range :: (Eq a, Eq b) => FinFun a b -> [b] apply :: (Eq a, Eq b) => FinFun a b -> a -> Maybe b
This function should be called as update(i,v) f where f is a finite function with domain a and codomain b. If i is the first element of any pair in f return the finite function that is just like f except that it maps i to v. If i is not the first element of any pair in f, return the finite function the behaves just like f but also contains the pair (i,v).
Call this predicate as functional m where m is a list of pairs. The predicate returns True iff for every pair (i,v)∈ m, there is no pair (j,v’) ∈ m with i=j.
This function returns a list of values in the domain a that the function is actually defined for.
This function returns a list of values in the codomain b that is the range of the finite function.
apply f x :: apply the finite function f to argument x and return Nothing if x 6 ∈ (domain f) and return Just y when the pair (x,y) ∈ f.
Exercise 1.2. Instantiate the type of finite functions FinFun as an instance of the Eq type class by defining == to be the extensional equality on functions. You can use the equality in the module Sets as a model, or you may even use it in your definition.
Recall that extensional equality for finite functions means the list representing the function is functional and they have the same elements.