0

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?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
MrD
  • 4,986
  • 11
  • 48
  • 90
  • 3
    The result of the last command is bound to the variable `it`. You can `writeFile "filename.txt" it`. Or `writefile "filename.txt" $ `. – vivian Mar 02 '14 at 03:32
  • 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 Mar 02 '14 at 12:17
  • @DarioP: If it is an instance of `Show`, just use `writeFile "filename.txt" $ show it`. – Zeta Mar 02 '14 at 12:42
  • @zeta I get "not in scope id, did you mean id"... thoughts? – MrD Mar 02 '14 at 13:02
  • 1
    @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 Mar 02 '14 at 13:51

1 Answers1

1

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>

vivian
  • 1,434
  • 1
  • 10
  • 13