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

Tyson Whitehead twhitehead at gmail.com
Wed Jun 8 20:25:11 CEST 2011


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110608/73ff3af6/attachment.pgp>


More information about the web-devel mailing list