{-# OPTIONS_GHC -fno-warn-missing-methods #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE FlexibleContexts #-}
module Fibonacci where
-- exercise 1
(+) (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