I may be missing something here, but this is what I intended.

An expression of the form

        1
a1 + ------
            1
    a2 + ------
                 1
         a3 + --
                 a4 + ...

Where the ai's are positive integers is called
a continued fraction.

Function cf should take [1,2,6,5] to produce

        1
  1 + -----
          1
    2 + -----
              1
        6 + --
              5

Michael


--- On Sat, 3/28/09, Brandon S. Allbery KF8NH <[email protected]> wrote:

From: Brandon S. Allbery KF8NH <[email protected]>
Subject: Re: [Haskell-cafe] type Rational and the % operator
To: "michael rice" <[email protected]>
Cc: "Brandon S. Allbery KF8NH" <[email protected]>, "Duane Johnson" 
<[email protected]>, [email protected]
Date: Saturday, March 28, 2009, 10:39 PM

On 2009 Mar 28, at 22:36, michael rice wrote:import Data.Ratio
cf :: [Integer] -> Rational
cf (x:xs) = (toRational x) + (1 % (cf xs))
cf (x:[]) = toRational x
cf [] = toRational 0

Data.Ratio> :load cf.hs
ERROR "cf.hs":3 - Type error in application
*** Expression     : toRational x + 1 % cf xs
*** Term           : toRational x
*** Type           : Ratio Integer
*** Does not match : Ratio (Ratio Integer)

Your function cf produces a Rational (Ratio Int); you're using it in the 
denominator of another Ratio, which makes that Ratio's type Ratio (Ratio Int).  
This is almost certainly not what you intended, but I couldn't say what you 
actually want.
 -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] 
[email protected] administrator [openafs,heimdal,too many hats] 
[email protected] and computer engineering, carnegie mellon 
university    KF8NH
 



      
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to