<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] -&gt; Rational<br>
cf (x:xs) = (x % 1) + (1 % (cf xs))<br>
cf (x:[]) = x % 1<br>
cf [] = 0 % 1<br>
<br>
Hugs&gt; :load cf.hs<br>
ERROR "cf.hs":3 - Type error in application<br>
*** Expression&nbsp;&nbsp;&nbsp;&nbsp; : x % 1 + 1 % cf xs<br>
*** Term&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : x % 1<br>
*** Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Ratio Integer<br>
*** Does not match : Ratio (Ratio Integer)<br>
<br>
Data.Ratio&gt; <br>
<br><br>--- On <b>Sat, 3/28/09, Ryan Ingram <i>&lt;ryani.spam@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Ryan Ingram &lt;ryani.spam@gmail.com&gt;<br>Subject: Re: [Haskell-cafe] type Rational and the % operator<br>To: "michael rice" &lt;nowgate@yahoo.com&gt;<br>Cc: "Brandon S. Allbery KF8NH" &lt;allbery@ece.cmu.edu&gt;, haskell-cafe@haskell.org<br>Date: Saturday, March 28, 2009, 11:17 PM<br><br><div class="plainMail">Just use "/" for division.&nbsp; % 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>&nbsp; -- ryan<br><br><br>2009/3/28 michael rice &lt;<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;:<br>&gt; I may be missing something here, but this is what I intended.<br>&gt;<br>&gt; An expression of the
 form<br>&gt;<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br>&gt; a1 + ------<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br>&gt; &nbsp;&nbsp;&nbsp; a2 + ------<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a3 + --<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a4 + ...<br>&gt;<br>&gt; Where the ai's are positive integers is called<br>&gt; a continued fraction.<br>&gt;<br>&gt; Function cf should take [1,2,6,5] to produce<br>&gt;<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br>&gt; &nbsp; 1 + -----<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br>&gt; &nbsp;&nbsp;&nbsp; 2 + -----<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br>&gt;
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6 + --<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5<br>&gt;<br>&gt; Michael<br>&gt;<br>&gt;<br>&gt; --- On Sat, 3/28/09, Brandon S. Allbery KF8NH &lt;<a ymailto="mailto:allbery@ece.cmu.edu" href="/mc/compose?to=allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>&gt; wrote:<br>&gt;<br>&gt; From: Brandon S. Allbery KF8NH &lt;<a ymailto="mailto:allbery@ece.cmu.edu" href="/mc/compose?to=allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>&gt;<br>&gt; Subject: Re: [Haskell-cafe] type Rational and the % operator<br>&gt; To: "michael rice" &lt;<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;<br>&gt; Cc: "Brandon S. Allbery KF8NH" &lt;<a ymailto="mailto:allbery@ece.cmu.edu" href="/mc/compose?to=allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>&gt;, "Duane Johnson"<br>&gt; &lt;<a ymailto="mailto:duane.johnson@gmail.com"
 href="/mc/compose?to=duane.johnson@gmail.com">duane.johnson@gmail.com</a>&gt;, <a ymailto="mailto:haskell-cafe@haskell.org" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a><br>&gt; Date: Saturday, March 28, 2009, 10:39 PM<br>&gt;<br>&gt; On 2009 Mar 28, at 22:36, michael rice wrote:<br>&gt;<br>&gt; import Data.Ratio<br>&gt; cf :: [Integer] -&gt; Rational<br>&gt; cf (x:xs) = (toRational x) + (1 % (cf xs))<br>&gt; cf (x:[]) = toRational x<br>&gt; cf [] = toRational 0<br>&gt;<br>&gt; Data.Ratio&gt; :load cf.hs<br>&gt; ERROR "cf.hs":3 - Type error in application<br>&gt; *** Expression&nbsp;&nbsp;&nbsp;&nbsp; : toRational x + 1 % cf xs<br>&gt; *** Term&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : toRational x<br>&gt; *** Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Ratio Integer<br>&gt; *** Does not match : Ratio (Ratio Integer)<br>&gt;<br>&gt; Your function cf produces a Rational (Ratio Int);
 you're using it in the<br>&gt; denominator of another Ratio, which makes that Ratio's type Ratio (Ratio<br>&gt; Int). &nbsp;This is almost certainly not what you intended, but I couldn't say<br>&gt; what you actually want.<br>&gt; --<br>&gt; 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>&gt; 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>&gt; electrical and computer engineering, carnegie mellon university &nbsp; &nbsp;KF8NH<br>&gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Haskell-Cafe mailing list<br>&gt; <a ymailto="mailto:Haskell-Cafe@haskell.org" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>&gt; <a
 href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>&gt;<br>&gt;<br></div></blockquote></td></tr></table><br>