Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parsec error in haskelwiki tutorial

Tags:

haskell

I was following the code in http://www.haskell.org/haskellwiki/Hitchhikers_guide_to_Haskell, and the code (in chapter 2) gives an error. There is no author name/email mentioned with the tutorial, so I am coming here for advise. The code is below, and the error occurs on the "eof" word.

module Main where

import Text.ParserCombinators.Parsec

parseInput = 
  do dirs <- many dirAndSize
     eof
     return dirs

data Dir = Dir Int String deriving Show

dirAndSize = 
  do size <- many1 digit
     spaces
     dir_name <- anyChar `manyTill` newline
     return (Dir (read size) dir_name)

main = do
    input <- getContents
    putStrLn ("Debug: got inputs: " ++ input)
like image 544
R71 Avatar asked Aug 14 '26 20:08

R71


1 Answers

That tutorial was written a long time ago, when parsec was simple. Nowadays, since parsec-3, the library can wrap monads, so you now have to specify (or otherwise disambiguate) the type to use at some points. This is one of them, giving eof e.g. the expression type signature eof :: Parser () makes it compile.

like image 143
Daniel Fischer Avatar answered Aug 17 '26 23:08

Daniel Fischer