[Haskell-cafe] Rational and % operator remix
michael rice
nowgate at yahoo.com
Sun Mar 29 13:40:19 EDT 2009
Hi,
Thanks again for the help last night.
The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, but you shouldn't get into trouble if you use 98%67 as input (output should be [1,2,6,5]). The interpreter is complaining about the '=' following the 'in' keyword. Is there a better way to state this?
Michael
import Data.Ratio
cf :: [Int] -> Rational
cf (x:[]) = toRational x
cf (x:xs) = toRational x + 1 / cf xs
cf2 :: Rational -> [Int]
cf2 a = let ai = toRational (floor ((numerator a) / (denominator a)))
in
if a = ai
then [a]
else ai : cf2 ((toRational 1) / (subtract ai a))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090329/285cae5b/attachment.htm
More information about the Haskell-Cafe
mailing list