From: Ramakrishnan Muthukrishnan Date: Mon, 22 Dec 2014 16:19:14 +0000 (+0530) Subject: hw6: implement instance of Fractional for Stream Integer X-Git-Url: https://git.rkrishnan.org/vdrive/%22news.html/frontends/running.html?a=commitdiff_plain;h=dbe21fbd73c1806b851f0b9141596be2f0b59e29;p=yorgey.git hw6: implement instance of Fractional for Stream Integer --- 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