- 论坛徽章:
- 0
|
- {-This is a program demostrates the calculating of the fraction
- progamming by Haskell
- -}
- qsort :: Ord a=> [a] -> [a]
- qsort [] = []
- qsort (x:xs) = qsort larger ++ [x] ++ qsort smaller
- where
- smaller =[ a|a <- xs,a<=x]
- larger = [ a| a <- xs ,a>x]
- type Fraction = (Int,Int )
- maxGYS :: Int -> Int -> Int --求最大公约数
- maxGYS m n
- | m<n =head [x | x <- qsort [1..m],m`mod` x==0, n`mod` x==0]
- | m == n =m
- | otherwise =head [ x| x <- qsort[1..n] , m`mod` x==0, n`mod` x==0]
- --maxGYS a b
-
- minGBS :: Int -> Int -> Int -- 求两个数的最小公倍数
- minGBS a b
- | a==b =a
- | a/=b =head[ x | x <- [a,2*a .. a*b] , x `mod` a ==0 , x `mod` b ==0 ]
- --simplify :: Int -> Int -> Fraction --约分函数
- simplify a b = if a == b then (1 , 1) else ( a / (maxGYS a b ) , b/ (maxGYS a b ) )
- --simplify a b = ( a / (maxGYS a b ) , b / (maxGYS a b ) )
-
- ratplus :: Fraction ->Fraction ->Fraction -- the plus calc
- ratplus (a,b) (c,d)
- | b==d = (a+c, b)
- | b /= d = ( a+(minGBS b d) /a+c+(minGBS b d) /c ,minGBS b d )
- --ratfloat :: Fraction -> Float -- convert to floating numbers
- --ratfloat (a,b) = (a :: Float ) / (b :: Float)
-
复制代码
winhugs下的出错信息是ERROR file:.\lab1.hs:25 - Instance of Fractional Int required for definition of simplify
也就是simplify函数的问题,请问应该怎么改呢? |
|