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

  • SEARCH
  • Home
  • 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 7782305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:29:59+00:00 2026-06-01T19:29:59+00:00

I want to do some tracing/debugging in my attoparsec parser. Here’s minimal [not] working

  • 0

I want to do some tracing/debugging in my attoparsec parser. Here’s minimal [not] working example:

import Data.Text as T
import Data.Attoparsec.Text
import Data.Attoparsec.Combinator
import Control.Applicative ((<*), (*>))

parseSentences :: Parser [T.Text]
parseSentences = many1 $ takeWhile1 (/= '.') <* char '.' <* skipSpace

parser :: Parser [T.Text] 
parser = do
    stuff <- parseSentences
--    putStrLn $ "Got stuff: " ++ show stuff

    tail <- takeText
--    putStrLn $ "Got tail: " ++ show tail

    return $ stuff ++ [tail, T.pack "more stuff"]

main = do
    let input = T.pack "sample. example. bang"
    print $ parseOnly parser input

What i have to do in order to use IO actions in my parser?

  • 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-06-01T19:30:01+00:00Added an answer on June 1, 2026 at 7:30 pm

    If you had used the Parsec library, you would have had the possibility of using the Parsec monad transformer for mixing IO and parser commands in your code.

    Attoparsec, however, is a pure parser, so you will have to use the Debug.Trace.trace function to output messages to the terminal for debugging purposes.

    parser = do
      stuff <- parseSentences
      tail <- takeText
      return .
        trace ("Got stuff: " + show stuff) .
        trace ("Got tail: "  + show tail) $
        stuff ++ [tail, T.pack "more stuff"]
    

    The messages will be printed when the associated value (here the result of the expression stuff ++ ...) is evaluated.

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

Sidebar

Related Questions

I want to implement some basic tracing in a simple c# (WPF) application that
I want some examples of C preprocessor directives, such as: #define pi 3.14 #define
I want some code to be triggered every second. Usually, I'd create a Timer
I want some of the goodies in a ListView, like being able to use
I want some like this: How make it ideologically correct?
I want some static pages of application to be rendered from XML i.e. i
Let's say I want some instance of String behave differently from other, normal instances
i am new in ssrs i want some sugeestiion from You can i use
May be it sound dumb but if I want some computed value from other
I am developing a library. I want some functionality to be additionally available in

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.