X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=hw6%2FFibonacci.hs;h=e7b3f591e86a5e301ac7407c457dacbade725796;hb=dbe21fbd73c1806b851f0b9141596be2f0b59e29;hp=9a1571253b8f1487ce2a6146a994e7c26d5e22a8;hpb=1adac606aa0f431ab41a698b763dbee3928cede7;p=yorgey.git diff --git a/hw6/Fibonacci.hs b/hw6/Fibonacci.hs index 9a15712..e7b3f59 100644 --- a/hw6/Fibonacci.hs +++ b/hw6/Fibonacci.hs @@ -2,6 +2,7 @@ {-# OPTIONS_GHC -fno-warn-missing-methods #-} {-# LANGUAGE InstanceSigs #-} {-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE FlexibleContexts #-} module Fibonacci where -- exercise 1 @@ -86,3 +87,9 @@ instance Num (Stream Integer) where (+) (Cons x sx) (Cons y sy) = (Cons (x+y) ((+) sx sy)) (*) :: 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 + (/) :: Stream Integer -> Stream Integer -> Stream Integer + (/) (Cons x xs) (Cons y ys) = let r = streamMap (/ y) $ Cons x ((xs - r*ys)) + in + r