Hello i want to ask fellow haskellers how can you debug haskell programs efficiently if you have a long chain of pure methods.E.g:
do
a<-impure
(pure a) # where pure calls pure1->pure2->pure2
How can i debug anything deep in the call stack if everything is not IO
,therefore i can't print
or writeFile
anywhere without significant effort ?
Do haskell fellows just change all signatures to IO something
to see where the code crashes?
Concrete example
Main
module Main where
import Data.Text(Text,pack,unpack)
import Data.Text.IO(readFile,writeFile)
import TCPFile(TCPFile)
import TCPEncoding(toText,fromText)
main::IO()
main=do
dat<-readTcpFile "test.txt"
print dat
writeTcpFile "output.txt" dat
writeTcpFile::FilePath->TCPFile->IO()
writeTcpFile path file=Data.Text.IO.writeFile path (toText file)
readTcpFile::FilePath->IO TCPFile
readTcpFile path =fromText <$> Data.Text.IO.readFile path
module TCPEncoding where
import Data.Text
class TextEncode a where
toText::a-> Text
fromText::Text-> a
I will not write the whole hierarchy of methods.I just want to know how can i run the program until a certain line and get the variable values and the stack frame.
In the case of this program all i get at the end written in my file with writeTcpFile
is:
main: <<loop>>
So how can i debug the fromText
method used inside readTcpFile
and its internals?