
I am wondering how can I ask ghci to show an infinite list wisely. When I type *fst ([1..],[1..10])* The result is what as you may guess *1,2,3,4,...*(continues to show, cut now) How could I may ghci show *[1..]* this wise way not the long long long list itself? Yi

Knowing whether a computation will terminate is in general the halting
problem, so immediately you're looking at a syntactic restriction.
Here the only ones I can think of are artificial at best (i.e., they
don't work for examples more than what you've shown here):
http://trac.haskell.org/haskell-platform/ticket/180
There was some discussion [1] on putting a limit to what the
interpreter prints out. Off the top of my head I suppose a hacky way
to do this would be to define a new type deriving show in a way that
printed out the list to some bounded depth.
Kris
[1] http://projects.haskell.org/pipermail/haskell-platform/2011-July/001619.html
On Tue, Jul 23, 2013 at 10:30 PM, yi lu
I am wondering how can I ask ghci to show an infinite list wisely. When I type
fst ([1..],[1..10])
The result is what as you may guess
1,2,3,4,...(continues to show, cut now)
How could I may ghci show
[1..]
this wise way not the long long long list itself?
Yi
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

This portion of haskell-mode (haskell-interactive-mode-eval-pretty) is what
the UI for something like this could look like:
https://www.youtube.com/watch?v=pu9AGSOySlE
This isn't an answer to your question, though, because expanding subparts
of the output doesn't drive evaluation. It would be very cool, and quite
possible, to have a variant of the Show typeclass that had output with such
structured laziness.
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.
-Michael
[0] http://hackage.haskell.org/package/vacuum
[1] http://hackage.haskell.org/package/vacuum-graphviz
[2] https://gist.github.com/mgsloan/6068915
On Tue, Jul 23, 2013 at 7:30 PM, yi lu
I am wondering how can I ask ghci to show an infinite list wisely. When I type
*fst ([1..],[1..10])*
The result is what as you may guess
*1,2,3,4,...*(continues to show, cut now)
How could I may ghci show
*[1..]*
this wise way not the long long long list itself?
Yi
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

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@joachim-breitner.de • http://www.joachim-breitner.de/ Jabber: nomeata@joachim-breitner.de • GPG-Key: 0x4743206C Debian Developer: nomeata@debian.org

The data-pprint package's pprint function might give you a quick fix.
For example:
Prelude> :m Data.PPrint
Prelude Data.PPrint> pprint [1..]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, …, ……]
Prelude Data.PPrint> let long_computation = long_computation
Prelude Data.PPrint> pprint [1, long_computation, 3]
[1, ⊥₁, 3]
⊥₁: timeout at 0%
It's a bit of a hassle to have to type "pprint" all the time though,
and it doesn't give you a way to show the data without printing to the
terminal in the IO monad.
On Wed, Jul 24, 2013 at 4:30 AM, yi lu
I am wondering how can I ask ghci to show an infinite list wisely. When I type
fst ([1..],[1..10])
The result is what as you may guess
1,2,3,4,...(continues to show, cut now)
How could I may ghci show
[1..]
this wise way not the long long long list itself?
Yi
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Jun Inoue

You might like to know about this option for ghci -interactive-print
I tested it with data-pprint though and it didn't work because it
returns an IO Doc instead of IO () (I assume). But if you wrote a
function that used that, returned the right type, cabal installed it
and put it in your .ghci, you would have your pprinting by default
whenever you use ghci.
On Wed, Jul 24, 2013 at 7:33 AM, Jun Inoue
The data-pprint package's pprint function might give you a quick fix. For example:
Prelude> :m Data.PPrint Prelude Data.PPrint> pprint [1..] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, …, ……] Prelude Data.PPrint> let long_computation = long_computation Prelude Data.PPrint> pprint [1, long_computation, 3] [1, ⊥₁, 3] ⊥₁: timeout at 0%
It's a bit of a hassle to have to type "pprint" all the time though, and it doesn't give you a way to show the data without printing to the terminal in the IO monad.
On Wed, Jul 24, 2013 at 4:30 AM, yi lu
wrote: I am wondering how can I ask ghci to show an infinite list wisely. When I type
fst ([1..],[1..10])
The result is what as you may guess
1,2,3,4,...(continues to show, cut now)
How could I may ghci show
[1..]
this wise way not the long long long list itself?
Yi
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Jun Inoue
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Thanks for the tip, David, I didn't know about that flag! Looks
really handy for playing with EDSLs, which is usually better off
displayed through Doc, but the default Show instance is indispensable
when I find a bug in the conversion to the Doc.
Unfortunately, though, I'd be reluctant to make data-pprint the
universal default as it is now. I forgot to mention this in my
previous post, but data-pprint doesn't let you customize the output
per-datatype. It just works generically over Data.Data instances and
the format is fixed to be the same as default Show instances (except
for lists, which are special-cased internally). So as annoying as the
explicit pprint is, I see it as a necessary evil. Perhaps I can
generalize its interface and send a patch. I have some ideas but
never got around to trying them.
On Wed, Jul 24, 2013 at 10:16 PM, David McBride
You might like to know about this option for ghci -interactive-print
I tested it with data-pprint though and it didn't work because it returns an IO Doc instead of IO () (I assume). But if you wrote a function that used that, returned the right type, cabal installed it and put it in your .ghci, you would have your pprinting by default whenever you use ghci.
On Wed, Jul 24, 2013 at 7:33 AM, Jun Inoue
wrote: The data-pprint package's pprint function might give you a quick fix. For example:
Prelude> :m Data.PPrint Prelude Data.PPrint> pprint [1..] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, …, ……] Prelude Data.PPrint> let long_computation = long_computation Prelude Data.PPrint> pprint [1, long_computation, 3] [1, ⊥₁, 3] ⊥₁: timeout at 0%
It's a bit of a hassle to have to type "pprint" all the time though, and it doesn't give you a way to show the data without printing to the terminal in the IO monad.
On Wed, Jul 24, 2013 at 4:30 AM, yi lu
wrote: I am wondering how can I ask ghci to show an infinite list wisely. When I type
fst ([1..],[1..10])
The result is what as you may guess
1,2,3,4,...(continues to show, cut now)
How could I may ghci show
[1..]
this wise way not the long long long list itself?
Yi
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Jun Inoue
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Jun Inoue
participants (6)
-
David McBride
-
Joachim Breitner
-
Jun Inoue
-
Kristopher Micinski
-
Michael Sloan
-
yi lu