[Haskell-cafe] How can I use ghci more wisely?

Joachim Breitner mail at joachim-breitner.de
Wed Jul 24 13:20:22 CEST 2013


Hi,

Am Mittwoch, den 24.07.2013, 01:41 -0700 schrieb Michael Sloan:
> Another non-answer is to take a look at using vaccum[0] and
> vaccum-graphviz[1] together, to get an idea of the heap structure of
> unforced values.  I've made a gist demonstrating how to use these to
> visualize the heap without forcing values[2].  This doesn't show any
> concrete values (as that would require some serious voodoo), but does
> show how the heap changes due to thunks being forced.

if you want to stay in GHCi with it you can use ghc-heapview instead of
vacuum:

Prelude> :script /home/jojo/.cabal/share/ghc-heap-view-0.5.1/ghci 
Prelude> let x = [1..]
Prelude> take 20 x
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
Prelude> :printHeap x
Prelude> :printHeap x
let x1 = S# 20
in S# 1 : S# 2 : S# 3 : S# 4 : S# 5 : S# 6 : S# 7 : S# 8 : S# 9 : S# 10 : S# 11 : S# 12 : S# 13 : S# 14 : S# 15 : S# 16 : S# 17 : S# 18 : S# 19 : x1 : _thunk x1 (S# 1)

For this kind of infinite values you don’t see its finite, but for
others you do:

Prelude> let inf = let x = "ha" ++ x in x
Prelude> take 20 inf
"hahahahahahahahahaha"
Prelude> :printHeap inf
let x1 = C# 'h' : C# 'a' : x1
in x1

Greetings,
Joachim



-- 
Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttp://www.joachim-breitner.de/
  Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0x4743206C
  Debian Developer: nomeata at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130724/ca932170/attachment.pgp>


More information about the Haskell-Cafe mailing list