[Haskell-beginners] Parse string with optional entries [Parsec]

Antoine Latter aslatter at gmail.com
Mon Aug 8 17:17:16 CEST 2011


On Mon, Aug 8, 2011 at 9:44 AM,  <Stefan.Lukasser-EE at infineon.com> wrote:
> Ah, thanks. The next step would then be to replace empty strings with Nothing, and the others with
> Just Value
>
> I forgot to mention that the values are Double.
> I tried the following:
>
> numberP :: Parser Double  -- From RWH
> numberP = do
>    s <- getInput
>    case readSigned readFloat s of
>        [(n, s')] -> n <$ setInput s'
>        _         -> empty
>  <?> "number"
>
> valueP :: Parser [Double]
> valueP = do
>    (many numberP) `sepBy` (char '\t')
>  <?> "value list"



More information about the Beginners mailing list