[web-devel] Yesod Monoid instance for Endo [Header]

Michael Snoyman michael at snoyman.com
Thu Jun 9 14:20:23 CEST 2011


On Wed, Jun 8, 2011 at 9:25 PM, Tyson Whitehead <twhitehead at gmail.com> wrote:
> Hi All,
>
> I've been working my way through Yesod and noticed an irregularity.
>
> The GGHanlder monad stack (Yesod/Handler.hs)
>
>  type GHInner s m monad a =
>    ReaderT (HandlerData s m) (
>      ErrorT HandlerContents (
>         WriterT (Endo [Header]) (
>            StateT GHState monad
>         )
>      )
>    ) a
>
> has a WriterT member based on "Endo [Header]", which is locally defined as
>
>  type Endo a = a -> a
>
> Therefore, unless I'm missing something, the Writer T Monoid instance must be
>
>  Monoid b => Monoid (a -> b)
>  Monoid [a]
>
> (i.e., an environment to list construct).  Assuming the results a finally
> extracted by applying [] (an empty environment), this would mean
>
>  addHeader = GHandler . lift . lift . tell . (:)
>
> degrades to (++), giving non-constant time concatenation.
>
> I'm thinking what was really meant was to use the Endo Monoid instance,
> thereby gaining the constant-time concatenation via function composition.
>
> Cheers!  -Tyson
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
>

Hi Tyson,

Awesome catch, that's most definitely what was intended. I'll apply a patch.

Thanks,
Michael



More information about the web-devel mailing list