[Haskell-beginners] Parsing a file

Francesco Ariis fa-ml at ariis.it
Wed Jan 26 14:43:43 UTC 2022


Il 26 gennaio 2022 alle 10:02 Roger Mason ha scritto:
> I'll need to check exactly how to use case for this, but before I do I
> have this question.
> 
> =Parsec.parse species "test species" "this that"= worked fine in my
> tests.  Why has `parse` changed changed its return type when invoked as
> 
> =Parsec.parse species "test species" eqatoms=
> 
> That is confusing (and off putting) and makes it hard to test ones code.

They work fine because — I suspect — you ran them *inside ghci* (which
is totally fine). When you are dealing with main (or any function inside
the IO monad) you need as usual to make things typecheck by providing
the correct data.

Simple quiz: do you understand why

    main :: IO ()
    main = "prova"

does nor work (nor compile) while

    main :: IO ()
    main = putStrLn "prova"

does? If you are not sure read the “I/O” section from Real World Haskell [1]
or any introductory material about Haskell and IO.
Keep learning & fire here again if you are not sure!
—F

[1] http://book.realworldhaskell.org/read/io.html


More information about the Beginners mailing list