Haskell numeric type hierarchy in SICP exercises -
I was recently learning Haskell and was talking to a friend who is working through SICP. We were eager to compare common Lisp and plan and so I decided to practice 1.29 as an exercise to try to translate into Haskell.
This exercise function uses sigma which represents the mathematical session function sigma. This function takes the function F to apply for each term, a function to apply a lower bound, the next term to apply on each term, and the upper bound gives it the amount of f applied to each term.
Simpson Antigrale is believed to use Simpson's law to estimate the integrality of function F on the boundary [A, B] using "Accuracy" N. I am having trouble working on this function because it seems that I do not know about the types involved.
This code will be compiled with the ghc version 6.12.1, but simpsonIntegral will be given a type of reference (Integral A, partial A) that does not make any sense and as soon as you call it . I have found this work at a job, but what I did was a sure hack that I wanted to ask here how to handle it idiomaticly.
How do integral -> frequency / actual conversion with a phrase be necessary? I have read many things but nothing is clear and clear.
Sigma :: (ord a, number b) => (A -> B) - & gt; A - & gt; (A -> A) - & gt; A - & gt; B sigma f next b = this one 0 where it is current acc current> B = ACC | Otherwise, = Iter (Next Present) (AC + F Content) Simpson Integral Fabien = 1.0 * (H / 3) * (Sigma Symmetrum 0 (1+) N) where H = (B - A) / N Simermerm K =) * Word where yk k = f (a + h * k) word = 0's case k - & gt; 1 1 - & gt; 1 otherwise - & gt; If weird Q then 4 and 2
To comply with the response to the Justice: If You are eager to put ' fromtetegral
s again, compile the following:
simpsonIntegral :: (Integral A, Fractional B) = & gt; (B -> B) - & gt; A - & gt; A - & gt; A - & gt; B simpsonIntegral fabn = 1.0 * (h / 3) * (sigma symmett 0 (1+) n) where h = from integral (b - a) / to integral n cement = (yak a) * words where yk k = f (FromIntegral A + H * from InterGal K) word = 0's case - & gt; 1 1 - & gt; 1 otherwise - & gt; If weird Kashmir then works for 4 and 2
and works:
* Main & gt; Simpson Integral (^ 3) 0 1 100 0.2533333233333334 * Main & gt; Simpson Integral (^ 3) 0 1 1000 0.2503333333323334
Comments
Post a Comment