
Hi, I’me writing a simple parser and can test it in GHCI parseTest moveParser "(1,2)->(3,3)” and I get what I expect i.e. Move {from = Location 1 2, to = Location 3 3} I now have a text file (test.txt) with lots of (1,2)->(3,3) (3,6)->(3,9) etc etc and I really can’t see how I get the contents of the text file into the parser!! I have main = do handle <- openFile "test.txt" ReadMode contents <- hGetContents handle !! what goes here!!! - how do I invoke moveParser with contents ?? Thanks Mike

It's hard to say exactly, but assuming you have your file new line
delimited and you have a function signature like
moveParser :: String -> YOUR_TYPE
you can try something like this:
main = do
handle <- openFile "test.txt"
contents <- hGetContents handle
processedLines <- return (fmap moveParser $ lines contents)
hClose handle
Does this help?
Dennis
On Sat, May 16, 2015 at 3:58 PM, Mike Houghton
Hi,
I’me writing a simple parser and can test it in GHCI
parseTest moveParser "(1,2)->(3,3)”
and I get what I expect i.e. Move {from = Location 1 2, to = Location 3 3}
I now have a text file (test.txt) with lots of (1,2)->(3,3) (3,6)->(3,9) etc etc and I really can’t see how I get the contents of the text file into the parser!!
I have main = do handle <- openFile "test.txt" ReadMode contents <- hGetContents handle !! what goes here!!! - how do I invoke moveParser with contents ??
Thanks
Mike
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

On Sat, 16 May 2015 23:18:04 +0200, Dennis J. McWherter, Jr.
processedLines <- return (fmap moveParser $ lines contents) :
Or, a bit simpler: let processedLines = fmap moveParser $ lines contents Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

Thanks guys. Finally got there and I’m sorry, I should have put more detail in the original question. movesParser :: Parser Moves movesParser = do move <- moveParser char ';' moves <- many moveParser return $ Moves ([move] ++ moves) main = do let mvsIo = readFile “moves.txt” — IO String mvs <- mvsIo — String let m = parse movesParser "Parsing Moves" mvs return m I must say that the people on this list are very helpful and polite. Also Haskell is a challenge but so rewarding. It’s become the ‘itch I have to scratch’. Thanks
On 17 May 2015, at 00:13, Henk-Jan van Tuyl
wrote: On Sat, 16 May 2015 23:18:04 +0200, Dennis J. McWherter, Jr.
wrote: :
processedLines <- return (fmap moveParser $ lines contents) :
Or, a bit simpler: let processedLines = fmap moveParser $ lines contents
Regards, Henk-Jan van Tuyl
-- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/
http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --
participants (3)
-
Dennis J. McWherter, Jr.
-
Henk-Jan van Tuyl
-
Mike Houghton