[Haskell] logic problem
michael at schmong.org
michael at schmong.org
Tue Oct 25 20:36:10 EDT 2005
Hi,
My name is Michael. I'm new to Haskell. I'm working through
The Craft of Functional Programming by Simon Thompson.
I'm having problems with a few exercises from chapter 4. I will
present one per post.
This one is from 4.9
Given a function f of type Int -> Int give a recursive definition
of a function of type Int -> Int which on input n returns the maximum
values f 0, f 1, ... , f n
I defined f as follows
f 0 = 0
f 1 = 44
f 2 = 5
f 9 = 8
this works except when f n > n. In that case I get an "illegal
instruction" error and hugs exits.
I'm pretty sure this is a logic problem. Could someone point me
in the right direction so I can think about this problem correctly.
Here is my code
maxOverf :: Int -> Int
maxOverf m
| f m > m = (f m)
| otherwise = (maxOverf m-1)
Any hints/help/flames welcome. Thanks
Michael Litchard
More information about the Haskell
mailing list