[Haskell-beginners] Parser

Dennis J. McWherter, Jr. dennis at deathbytape.com
Sat May 16 21:18:04 UTC 2015


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 <mike_k_houghton at yahoo.co.uk>
wrote:

> 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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150516/f6668f7c/attachment.html>


More information about the Beginners mailing list