[Haskell-beginners] type class question

Daniel Fischer daniel.is.fischer at web.de
Fri Sep 18 11:28:06 EDT 2009


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 ?


More information about the Beginners mailing list