First of all I would like to let you know that I'm fairly new to Haskell and I'm trying to understand how parsers work in haskell . So I'm basically trying to parse this e-book from http://www.gutenberg.org/files/57071/57071-0.txt and analyze the text. Like output the number of english words, sentences and paragraphs and such. Here's my code:
{-# LANGUAGE OverloadedStrings #-}
import Control.Exception (catch, SomeException)
import System.Environment (getArgs)
import Data.Attoparsec.Text
import Data.Char
import Control.Applicative ((<*>), (*>), (<$>), (<|>), pure)
data Prose = Prose {
word :: String
} deriving Show
prose :: Parser Prose
prose = do
word <- many' $ satisfy isAlphaNum
return $ Prose word
main :: IO()
main = do
input <- readFile "small.txt"
print $ parse prose input
This is my error message:
- Couldn't match type ‘[Char]’ with ‘Data.Text.Internal.Text’;
Expected type: Data.Text.Internal.Text;
Actual type: String - In the second argument of ‘parse’, namely ‘input’ In the second argument of ‘($)’, namely ‘parse prose input’ In a stmt of a 'do' block: print $ parse prose input
I have used "OverloadedStrings" to try and fix this issue, but it doesnt seem to work. Also any guidance on examples or tutorials to get started with attoparsec would be greatly helpful!