title: Parse fixed length text with attoparsec
body: <p>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:</p>
  
  <pre><code>&gt; {-# LANGUAGE OverloadedStrings #-}
  &gt; import Control.Applicative
  &gt; import Data.Text as T
  &gt; import Data.Attoparsec.Combinator
  &gt; import Data.Attoparsec.Text hiding (take)
  &gt; import Data.Char
  &gt; import Prelude hiding (take)
  &gt;
  &gt; type City = Text
  &gt; type Ready = Bool
  &gt; data CityReady = CR City Ready deriving Show
  &gt;
  &gt; input = T.unlines ["#London              1",
  &gt;                    "#Seoul               0",
  &gt;                    "#Tokyo               0",
  &gt;                    "#New York            1"]
  &gt;
  &gt; parseCityReady = many $ CR &lt;$&gt; cityParser &lt;*&gt; readyParser &lt;* endOfLine
  &gt;
  &gt; cityParser = char '#' *&gt;
  &gt;              takeTill isSpace &lt;*
  &gt;              skipWhile isHorizontalSpace
  &gt;
  &gt;
  &gt; readyParser = char '1' *&gt; pure True  &lt;|&gt; char '0' *&gt; pure False
  &gt;
  &gt; main =
  &gt;   case parseOnly parseCityReady input of
  &gt;      Left err  -&gt; print err
  &gt;      Right xs  -&gt; mapM_ print xs
  &gt;
  </code></pre>
  
  <p>This is all great but it is only returning Cities without spaces.</p>
  
  <pre><code>CR "London" True
  CR "Seoul" False
  CR "Tokyo" False
  </code></pre>
  
  <p>I have tried using applicative to take 20 characters for the City text string</p>
  
  <pre><code>&gt; cityParser = char '#' *&gt;
  &gt;              take 20
  </code></pre>
  
  <p>and even <code>do syntax</code></p>
  
  <pre><code>&gt; cityParser = do char '#'
  &gt;                 city &lt;- take 20
  &gt;                 return city
  </code></pre>
  
  <p>but both approaches fail to compile with this error:</p>
  
  <pre><code>Couldn't match expected type `attoparsec-0.10.4.0:Data.Attoparsec.Internal.Types.Parser
                                  Text b0'
              with actual type `Text -&gt; Text'
  In the return type of a call of `take'
  Probable cause: `take' is applied to too few arguments
  In the second argument of `(*&gt;)', namely `take 20'
  In the expression: char '#' *&gt; take 20
  </code></pre>
  
  <p>What is causing the ghc to ask for <code>Text -&gt; Text</code> when the <code>take</code> has a type of <code>Int -&gt; Text -&gt; Text</code>?</p>
  
  <p>How do I solve it in both applicative and do-syntax?</p>