From dbe21fbd73c1806b851f0b9141596be2f0b59e29 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Mon, 22 Dec 2014 21:49:14 +0530 Subject: [PATCH] hw6: implement instance of Fractional for Stream Integer --- hw6/Fibonacci.hs | 7 +++++++ 1 file changed, 7 insertions(+) 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 -- 2.37.2