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 9258769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:29:32+00:00 2026-06-18T12:29:32+00:00

I need to parse fixed length fields with attoparsec but im now struggling with

  • 0

I need to parse fixed length fields with attoparsec but im now struggling with the compiler.
Im still a newbie, the code below is the closest solution I have:

> {-# LANGUAGE OverloadedStrings #-}
> import Control.Applicative
> import Data.Text as T
> import Data.Attoparsec.Combinator
> import Data.Attoparsec.Text hiding (take)
> import Data.Char
> import Prelude hiding (take)
>
> type City = Text
> type Ready = Bool
> data CityReady = CR City Ready deriving Show
>
> input = T.unlines ["#London              1",
>                    "#Seoul               0",
>                    "#Tokyo               0",
>                    "#New York            1"]
>
> parseCityReady = many $ CR <$> cityParser <*> readyParser <* endOfLine
>
> cityParser = char '#' *>
>              takeTill isSpace <*
>              skipWhile isHorizontalSpace
>
>
> readyParser = char '1' *> pure True  <|> char '0' *> pure False
>
> main =
>   case parseOnly parseCityReady input of
>      Left err  -> print err
>      Right xs  -> mapM_ print xs
>

This is all great but it is only returning Cities without spaces.

CR "London" True
CR "Seoul" False
CR "Tokyo" False

I have tried using applicative to take 20 characters for the City text string

> cityParser = char '#' *>
>              take 20

and even do syntax

> cityParser = do char '#'
>                 city <- take 20
>                 return city

but both approaches fail to compile with this error:

Couldn't match expected type `attoparsec-0.10.4.0:Data.Attoparsec.Internal.Types.Parser
                                Text b0'
            with actual type `Text -> Text'
In the return type of a call of `take'
Probable cause: `take' is applied to too few arguments
In the second argument of `(*>)', namely `take 20'
In the expression: char '#' *> take 20

What is causing the ghc to ask for Text -> Text when the take has a type of Int -> Text -> Text?

How do I solve it in both applicative and do-syntax?

  • 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-18T12:29:34+00:00Added an answer on June 18, 2026 at 12:29 pm

    So, your problem is that you are hiding several versions of the take
    function. In particular, you are hiding the take from attoparsec rather
    than the take function from the Text module. All you should need to do is
    change your imports like so

    > import Control.Applicative
    > import Data.Attoparsec.Combinator
    > import Data.Attoparsec.Text
    > import Data.Char
    > import Data.Text as T hiding (take)
    > import Prelude hiding (take)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to parse complex (non fixed length) csv files to Java objects in
I need to parse the payload from different push notification, but if user press
I'm no expert in regex but I need to parse some input I have
I need parse through a file and do some processing into it. The file
Hi I need parse and deserialize pseudo JSON string. Input data: {aBubbleData[ 'jaja2581' ]={
Need to parse a file for lines of data that start with this pattern
I need to parse a protocol buffer send via a post using bottle. How
I need to parse a duration string, of the form 98d 01h 23m 45s
I need to parse through a string and add single quotes around each Guid
I need to parse a JSON string in my project, which runs on BB

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.