I am trying to write the power series in Haskell,
e^x = 1 + x + x^2/2! + x^3/3! + ...
such that it will out put
[1,1,1/2,1/6,...]
so far I got:
factorial 0 = 1
factorial n = n * factorial (n - 1)
powerSrs x = 1 : powerSrsFunc[1..] where
powerSrsFunc ( p: xs ) =
p : powerSrsFunc[y | y <-xs, ( (x^y) / (factorial y) )]
However, I understand that my typing here is wrong. I am getting this error:
tut08.hs:8:58:
No instance for (Integral Bool)
arising from a use of `^'
Possible fix: add an instance declaration for (Integral Bool)
In the first argument of `(/)', namely `(x ^ y)'
In the expression: ((x ^ y) / (factorial y))
In a stmt of a list comprehension: ((x ^ y) / (factorial y))
tut08.hs:8:62:
No instance for (Fractional Bool)
arising from a use of `/'
Possible fix: add an instance declaration for (Fractional Bool)
In the expression: ((x ^ y) / (factorial y))
In a stmt of a list comprehension: ((x ^ y) / (factorial y))
In the first argument of `powerSrsFunc', namely
`[y | y <- xs, ((x ^ y) / (factorial y))]'
1) How do you write fractions in Haskell such that it is output like '1/2'?
2) What does it mean when they say No instance for (Integral Bool) and (Fractional Bool)?
Is it referring to two arguments that are of type Integral and Bool?
Does it not take Integral and Integral?