0
votes

I am trying to simulate the taylor polynomial of e^x

---Macularian for e^x 
e :: (Num a) => a -> Int -> a
e value precsion = sum $ take precsion [((x^n) / product [1..n]) | x <- value, n <- [0..]]

This is my error

Main.hs@3:73-3:78 Could not deduce (a ~ [a]) from the context (Num a) bound by the type signature for e :: Num a => a -> Int -> a at /home/app/isolation-runner-work/projects/75872/session.207/src/Main.hs:2:6-29 a is a rigid type variable bound by the type signature for e :: Num a => a -> Int -> a at /home/app/isolation-runner-work/projects/75872/session.207/src/Main.hs:2:6 Relevant bindings include value :: a (bound at /home/app/isolation-runner-work/projects/75872/session.207/src/Main.hs:3:3) e :: a -> Int -> a (bound at /home/app/isolation-runner-work/projects/75872/session.207/src/Main.hs:3:1) …

1
By the way, this is not a "crash" of the compiler, or of your program. It's just a type error.chi

1 Answers

5
votes

This part: x <- value means that value is a list. If you change it to let x = value (or just rename value to x you will fix that specific compile error:

e x precision = take precision [ ...formula involving x and n... | n <- [0..] ]

You might then run into another compiler error involving your type signature, so I would comment that out and then have ghci tell you what the signature should be using :type command.