<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Works like a charm. Here's a final copy for those interested.<br><br>Michael<br><br>=====<br><br>import Data.Ratio<br>cf2 :: Rational -> [Int]<br>cf2 a = let ai = floor a<br> air = toRational ai<br> in ai : if a == air then [] else cf2 (1 / (a - air))<br><br><br><br>--- On <b>Sun, 3/29/09, Miguel Mitrofanov <i><miguelimo38@yandex.ru></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Miguel Mitrofanov <miguelimo38@yandex.ru><br>Subject: Re: [Haskell-cafe] Rational and % operator remix<br>To: "michael rice" <nowgate@yahoo.com><br>Cc: "Lennart Augustsson" <lennart@augustsson.net>, haskell-cafe@haskell.org<br>Date: Sunday, March 29, 2009, 4:25 PM<br><br><div
class="plainMail">cf2 a = let ai = floor a<br> air = toRational ai<br> in ai : if a == air then [] else cf2 (1 / (a - air))<br><br>On 30 Mar 2009, at 00:19, michael rice wrote:<br><br>> I'm a Lisper, kind of feeling my way around here in Haskell, so please bear with me.<br>> <br>> I did the things you suggested, but I think the last one may have gotten garbled. Anyway, this is what I ended up with<br>> <br>> cf2 :: Rational -> [Int]<br>> cf2 a = let ai = floor a<br>> in<br>> if a == (toRational ai)<br>> then [ai]<br>> else ai : cf2 (1 / (a - ai))<br>> <br>> but I'm still at least one error short of a clean
run<br>> <br>> Main> :load cf.hs<br>> ERROR "cf.hs":7 - Type error in application<br>> *** Expression : ai : cf2 (1 / (a - ai))<br>> *** Term : ai<br>> *** Type : Ratio Integer<br>> *** Does not match : Int<br>> <br>> <br>> Where did I go wrong or what did I leave out?<br>> <br>> Michael<br>> <br>> <br>> --- On Sun, 3/29/09, Lennart Augustsson <<a ymailto="mailto:lennart@augustsson.net" href="/mc/compose?to=lennart@augustsson.net">lennart@augustsson.net</a>> wrote:<br>> <br>> From: Lennart Augustsson <<a ymailto="mailto:lennart@augustsson.net" href="/mc/compose?to=lennart@augustsson.net">lennart@augustsson.net</a>><br>> Subject: Re: [Haskell-cafe] Rational and % operator remix<br>> To: "michael rice" <<a ymailto="mailto:nowgate@yahoo.com"
href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>><br>> Cc: <a ymailto="mailto:haskell-cafe@haskell.org" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a><br>> Date: Sunday, March 29, 2009, 2:29 PM<br>> <br>> You can use floor in a Rational directly, no need to take it apart and divide.<br>> <br>> There is no need to write (toRational 1), just write 1.<br>> <br>> Don't write (subtract ai a), write (ai - i).<br>> <br>> You also have a type error; the ai should no be a Rational, so you<br>> need to move to toRational call to the comparison.<br>> <br>> -- Lennart<br>> <br>> 2009/3/29 michael rice <<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>>:<br>> > Hi,<br>> ><br>> > Thanks again for the help last night.<br>> ><br>> > The second function cf2 is an attempt to
reverse the process of the first<br>> > function, i.e., given a rational number it returns a list of integers,<br>> > possibly infinite, but you shouldn't get into trouble if you use 98%67 as<br>> > input (output should be [1,2,6,5]). The interpreter is complaining about the<br>> > '=' following the 'in' keyword. Is there a better way to state this?<br>> ><br>> > Michael<br>> ><br>> > import Data.Ratio<br>> > cf :: [Int] -> Rational<br>> > cf (x:[]) = toRational x<br>> > cf (x:xs) = toRational x + 1 / cf xs<br>> ><br>> > cf2 :: Rational -> [Int]<br>> > cf2 a = let ai = toRational (floor ((numerator a) / (denominator a)))<br>> > in<br>> > if a = ai<br>> > then [a]<br>>
> else ai : cf2 ((toRational 1) / (subtract ai a))<br>> ><br>> ><br>> ><br>> > _______________________________________________<br>> > Haskell-Cafe mailing list<br>> > <a ymailto="mailto:Haskell-Cafe@haskell.org" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>> > <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>> ><br>> ><br>> <br>> _______________________________________________<br>> Haskell-Cafe mailing list<br>> <a ymailto="mailto:Haskell-Cafe@haskell.org" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe"
target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br><br></div></blockquote></td></tr></table><br>