{- Code transcribed from M. Douglas McIlroy, Power Series, Power Serious, JFP 1998 Functional Pearl. -} default (Integer,Rational,Float) ps0, ps1, x :: Num a => [a] ps0 = 0 : ps0 x = 0 : 1 : ps0 ps1 = 1 : ps1 infix 7 .* (.*) :: Num a => a ->[a]->[a] c .* (f:fs) = c*f : c.*fs instance Num a => Num [a] where fromInteger c = (fromInteger c) : (fromInteger 0) negate (f:fs) = -f : -fs (f:fs) + (g:gs) = f+g : fs+gs (f:fs) * (g:gs) = (f*g : 0) + (0 : f.*gs + g.*fs) + (0 : 0 : fs*gs) instance Fractional a => Fractional [a] where (0:fs) / (0:gs) = fs/gs (f:fs) / (g:gs) = let q = f/g in q : (fs - q.*gs)/(g:gs) compose (f:fs) (0:gs) = f : gs*(compose fs (0:gs)) revert (0:fs) = rs where rs = 0 : 1/(compose fs rs) deriv (f:fs) = (deriv1 fs 1) where deriv1 (g:gs) n = n*g : (deriv1 gs (n+1)) integral fs = 0 : (int1 fs 1) where int1 (g:gs) n = g/n : (int1 gs (n+1)) expx = 1 + (integral expx) sinx = integral cosx cosx = 1 - (integral sinx) tanx = revert (integral (1/(1+x*x)))