I have a Haskell function which returns quite a large output. (In fact, beyond the console's buffer size.) Is there any way GHCI output can be automatically saved to an external txt file rather than simply displayed?
The result of the last command is bound to the variable it. You can writeFile "filename.txt" it. Or writefile "filename.txt" $ <statement>.
– vivian
Tried that, not working. The point is my function returns [Integer] and writeFile seems to expect [Char]. Any ideas on how I could fix that? @vivian
– MrD
@DarioP: If it is an instance of Show, just use writeFile "filename.txt" $ show it.
– Zeta
@zeta I get "not in scope id, did you mean id"... thoughts?
– MrD
@DarioP: Yes - it stores the result of the last command. If there hasn't been a last statement with a value (for instance, all statements have been let ... expressions), it will be not in scope. So basically take vivian's comment, but put a $ show before your statements.
– Zeta
1 Answers
1
votes
The result of the last command is bound to the variable it.
You can
writeFile "filename.txt" $ show it
or
writefile "filename.txt" $ show $ <statement>
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more
it
. You canwriteFile "filename.txt" it
. Orwritefile "filename.txt" $ <statement>
. – vivianShow
, just usewriteFile "filename.txt" $ show it
. – Zetait
stores the result of the last command. If there hasn't been a last statement with a value (for instance, all statements have beenlet ...
expressions),it
will be not in scope. So basically take vivian's comment, but put a$ show
before your statements. – Zeta