Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5946195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:47:18+00:00 2026-05-22T16:47:18+00:00

From http://happstack.com/docs/crashcourse/HappstackState.html When I run the server, the peek counter increases by 1 when

  • 0

From

http://happstack.com/docs/crashcourse/HappstackState.html

When I run the server, the peek counter increases by

  • 1 when I peek
  • 2 when I do not peek

The relevant code in question is:

handlers :: ServerPart Response
handlers = 
    msum [ dir "peek" $ do c <- query PeekCounter
                       ok $ toResponse $ "peeked at the count and saw: " ++ show (unCounter c)
         , do c <- update (AddCounter 1)
           ok $ toResponse $ "New count is: " ++ show (unCounter c)
         ]

However, when I modify it to

handlers :: ServerPart Response
handlers = 
    msum [ dir "peek" $ do c <- query PeekCounter
                           ok $ toResponse $ "peeked at the count and saw: " ++ show (unCounter c)
         , do ok $ toResponse $ "Stop here."
         , do c <- update (AddCounter 1)
              ok $ toResponse $ "New count is: " ++ show (unCounter c)
         ]

The counter increases by

  • 0 when I peek
  • 1 when I non-peek

Is that the intended behaviour? It feels as if the second monad in msum is “leaking” even when I do a peek.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:47:19+00:00Added an answer on May 22, 2026 at 4:47 pm

    The count is being incremented an extra time because the browser requests /favicon.ico every time it loads the page. Since the last route is a catch-all, the request to /favicon.ico causes an increment.

    The easiest fix is to add nullDir so that it only does an increment for /,

    handlers :: ServerPart Response
    handlers = 
    msum [ dir "peek" $ do c <- query PeekCounter
                       ok $ toResponse $ "peeked at the count and saw: " ++ show (unCounter c)
         , do nullDir
              c <- update (AddCounter 1)
              ok $ toResponse $ "New count is: " ++ show (unCounter c)
         ]
    

    I have updated the tutorial with that change to avoid further confusion. To confirm that it really is the /favicon.ico request that is messing things up, we could explicitly handle the request for a favicon:

    handlers :: ServerPart Response
    handlers = 
        msum [ dir "peek" $ do c <- query PeekCounter
                               ok $ toResponse $ "peeked at the count and saw: " ++ show (unCounter c)
             , dir "favicon.ico" $ notFound (toResponse "sorry, no favicon.ico")
             , do c <- update (AddCounter 1)
                  ok $ toResponse $ "New count is: " ++ show (unCounter c)
             ]
    

    Now we see the expected behavior.

    In summary, there is nothing wrong with Happstack. The browser was making 1 or 2 requests to urls that were not /peek, and so the count got incremented once or twice. That was the intended behavior of the application. But, since people aren’t expecting the /favicon.ico request it also leads to surprising behavior. So now the app has been change to only have two valid urls, /peek and /. Anything else results in a 404.

    Thanks for the report!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From http://developer.yahoo.com/yui/docs/YAHOO.util.DataSourceBase.html#method_sendRequest , you can see the oCallback is an object literal with the
From: http://doc.qt.nokia.com/4.7/signalsandslots.html Callbacks have two fundamental flaws: Firstly, they are not type-safe. We can
From http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html#99740 example A3.3 says, it says that an object might still not be
From http://code.google.com/appengine/docs/python/tools/webapp/running.html Tip: App Engine routes requests to Python scripts based on the URL
From http://www.jibbering.com/faq/faq_notes/closures.html : Note: ECMAScript defines an internal [[prototype]] property of the internal Object
a) Quote is taken from http://www.postgresql.org/docs/current/static/tutorial-window.html for each row, there is a set of
From http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeArguments.html#FAQ103 : A wildcard with a lower bound looks like ? super Type
From http://developer.android.com/guide/topics/fundamentals.html : It's possible to arrange for two applications to share the same
Using the Generator class from http://unpythonic.blogspot.com/2007/08/using-threads-in-pygtk.html , the following code makes my program fail:
Python documentation from http://docs.python.org/library/string.html : string.lstrip(s[, chars]) Return a copy of the string with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.