Haskell Number Type Issues

I have the following haskell code:

fac n = product [1..n]

taylor3s w0 f f' f'' t h = w1 : taylor3s w1 f f' f'' (t+h) h
  where hp i = h^i / fac i
        w1 = w0 + (hp 1) * f t w0 + (hp 2) * f' t w0 + (hp 3) * f'' t w0

taylor_results = take 4 $ taylor3s 1 f f' f'' 1 0.25
  where f   t x = t^4 - 4*x/t
        f'  t x = 4*t^3 - 4*(f t x)/t + 4*x/t^2
        f'' t x = 12*t^2 - 4*(f' t x)/t + 8*(f t x)/t^2 - 8*x/t^3

taylor_results is supposed to be used to use taylor3s. However, there is something wrong with the number entry method. When I try to compile, this is the error I get:

practice.hs:93:26:
    Ambiguous type variable `a' in the constraints:
      `Integral a'
        arising from a use of `taylor3s' at practice.hs:93:26-51
      `Fractional a' arising from a use of `f' at practice.hs:93:37
    Possible cause: the monomorphism restriction applied to the following:
      taylor_results :: [a] (bound at practice.hs:93:0)
    Probable fix: give these definition(s) an explicit type signature
                  or use -XNoMonomorphismRestriction

Can someone help me figure out what the problem is?

+5
source share
2 answers

, , ( , ^, ), **, Floating), haskell , taylor3s Fractional a, Integral a => a. , , , , .

, , , taylor_results Fractional a, Integral a => a, , , .

taylor_results taylor_results :: Fractional a, Integral a => a , , ( , Integral Fractional, ).

, (, ^ **), taylor_results ( taylor_results :: (Floating a, Enum a) => [a], ), . , - , taylor_results taylor_results , Floating Enum (, Double). : , taylor_results , ( ).

: (, ^ **), taylor_results (Floating a, Enum a) => [a], , ( ), be [Double]. , taylor_results ( Floating Enum), . : , taylor_results , ( ).

+8

, Haskell return taylor3s Integral, , f .. Fractional, .

, Haskell taylor3s.

0

All Articles