From: Ramakrishnan Muthukrishnan Date: Mon, 22 Dec 2014 16:35:36 +0000 (+0530) Subject: bug fix in Fractional instance X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/running.html?a=commitdiff_plain;h=0ee67caa13dc6a0810fa6938b56fba579c67b847;p=yorgey.git bug fix in Fractional instance --- diff --git a/hw6/Fibonacci.hs b/hw6/Fibonacci.hs index e7b3f59..15b563b 100644 --- a/hw6/Fibonacci.hs +++ b/hw6/Fibonacci.hs @@ -88,8 +88,11 @@ instance Num (Stream Integer) where (*) :: Stream Integer -> Stream Integer -> Stream Integer (*) (Cons x sx) (Cons y sy) = Cons (x*y) ((streamMap (* x) sy) + sx*(Cons x sx)) -instance Fractional Integer => Fractional (Stream Integer) where +-- instance Fractional Integer => Fractional (Stream Integer) where +instance Fractional (Stream Integer) where (/) :: Stream Integer -> Stream Integer -> Stream Integer - (/) (Cons x xs) (Cons y ys) = let r = streamMap (/ y) $ Cons x ((xs - r*ys)) + (/) (Cons x xs) (Cons y ys) = let r = streamMap (`div` y) $ Cons x ((xs - r*ys)) in r +fibs3 :: Stream Integer +fibs3 = x' / (streamRepeat 1 - x' - x' * x')