<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Still the same problem. The book says the answer is supposed to be an exact 98/67.<br><br>Michael<br>
<br>
import Data.Ratio<br>
cf :: [Integer] -> Rational<br>
cf (x:xs) = (x % 1) + (1 % (cf xs))<br>
cf (x:[]) = x % 1<br>
cf [] = 0 % 1<br>
<br>
Hugs> :load cf.hs<br>
ERROR "cf.hs":3 - Type error in application<br>
*** Expression : x % 1 + 1 % cf xs<br>
*** Term : x % 1<br>
*** Type : Ratio Integer<br>
*** Does not match : Ratio (Ratio Integer)<br>
<br>
Data.Ratio> <br>
<br><br>--- On <b>Sat, 3/28/09, Ryan Ingram <i><ryani.spam@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Ryan Ingram <ryani.spam@gmail.com><br>Subject: Re: [Haskell-cafe] type Rational and the % operator<br>To: "michael rice" <nowgate@yahoo.com><br>Cc: "Brandon S. Allbery KF8NH" <allbery@ece.cmu.edu>, haskell-cafe@haskell.org<br>Date: Saturday, March 28, 2009, 11:17 PM<br><br><div class="plainMail">Just use "/" for division. % is for construction of rationals from<br>the "underlying" numeric type.<br><br>For example, instead of "toRational x" you can write "x % 1".<br><br> -- ryan<br><br><br>2009/3/28 michael rice <<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>>:<br>> I may be missing something here, but this is what I intended.<br>><br>> An expression of the
form<br>><br>> 1<br>> a1 + ------<br>> 1<br>> a2 + ------<br>> 1<br>> a3 + --<br>> a4 + ...<br>><br>> Where the ai's are positive integers is called<br>> a continued fraction.<br>><br>> Function cf should take [1,2,6,5] to produce<br>><br>> 1<br>> 1 + -----<br>> 1<br>> 2 + -----<br>> 1<br>>
6 + --<br>> 5<br>><br>> Michael<br>><br>><br>> --- On Sat, 3/28/09, Brandon S. Allbery KF8NH <<a ymailto="mailto:allbery@ece.cmu.edu" href="/mc/compose?to=allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>> wrote:<br>><br>> From: Brandon S. Allbery KF8NH <<a ymailto="mailto:allbery@ece.cmu.edu" href="/mc/compose?to=allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>><br>> Subject: Re: [Haskell-cafe] type Rational and the % operator<br>> To: "michael rice" <<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>><br>> Cc: "Brandon S. Allbery KF8NH" <<a ymailto="mailto:allbery@ece.cmu.edu" href="/mc/compose?to=allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>>, "Duane Johnson"<br>> <<a ymailto="mailto:duane.johnson@gmail.com"
href="/mc/compose?to=duane.johnson@gmail.com">duane.johnson@gmail.com</a>>, <a ymailto="mailto:haskell-cafe@haskell.org" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a><br>> Date: Saturday, March 28, 2009, 10:39 PM<br>><br>> On 2009 Mar 28, at 22:36, michael rice wrote:<br>><br>> import Data.Ratio<br>> cf :: [Integer] -> Rational<br>> cf (x:xs) = (toRational x) + (1 % (cf xs))<br>> cf (x:[]) = toRational x<br>> cf [] = toRational 0<br>><br>> Data.Ratio> :load cf.hs<br>> ERROR "cf.hs":3 - Type error in application<br>> *** Expression : toRational x + 1 % cf xs<br>> *** Term : toRational x<br>> *** Type : Ratio Integer<br>> *** Does not match : Ratio (Ratio Integer)<br>><br>> Your function cf produces a Rational (Ratio Int);
you're using it in the<br>> denominator of another Ratio, which makes that Ratio's type Ratio (Ratio<br>> Int). This is almost certainly not what you intended, but I couldn't say<br>> what you actually want.<br>> --<br>> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] <a ymailto="mailto:allbery@kf8nh.com" href="/mc/compose?to=allbery@kf8nh.com">allbery@kf8nh.com</a><br>> system administrator [openafs,heimdal,too many hats] <a ymailto="mailto:allbery@ece.cmu.edu" href="/mc/compose?to=allbery@ece.cmu.edu">allbery@ece.cmu.edu</a><br>> electrical and computer engineering, carnegie mellon university KF8NH<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></div></blockquote></td></tr></table><br>