
27 Sep
2010
27 Sep
'10
12:08 p.m.
On Mon, Sep 27, 2010 at 05:41:24PM +0200, Martin Tomko wrote:
Dear all
I am sure this is a very beginner problem, but I am not sure how to solve it: I have a myFunct function: myFunct :: Int -> [a] -> a
defined as: myFunct _ [] = error "empty list provided as arg" myFunct a [b] | length [x|x<-[b],fid x == a] == 0 = error "no match" | otherwise = head [x|x<-[b],fid x == a]
May I also suggest that instead of implementing this yourself, you could just use myFunct a b = find ((==a) . fid) b 'find' is from Data.List and returns the first thing in the list satisfying the given predicate, or Nothing if there is no such element. -Brent