
18 Sep
2009
18 Sep
'09
11:28 a.m.
Am Freitag 18 September 2009 16:38:19 schrieb Ben:
instance Summarizer RunningAverageState (State RunningAverageState) where initialState = S 0 0 runOne = runningAverage
but how would i use this, e.g.
--summarizeMany vs = last $ evalState (mapM runOne vs) initialState
does not compile.
No, summarizeMany would have the type (Summarizer m s) => [Double] -> Double which is ambiguous. You would have to make m somehow accessible (dummy argument?).
1) what am i doing wrong? what are the right type class and instance declarations?
2) is there a better way of expressing this kind of "on-line" calculation, perhaps in pure (non-monadic) functions?
Perhaps scanl ?