+qsort2.hs:2:15-46>
+</programlisting>
+ What is happening here is that GHCi has interrupted the evaluation of
+ <literal>qsort</literal> at the breakpoint set in line 2, as the prompt indicates.
+ At this point you can freely explore the contents of the bindings in scope,
+ but with two catches. </para><para>
+ First, take into account that due to the lazy nature of Haskell, some of
+ these bindings may be unevaluated, and that exploring their contents may
+ trigger a computation. </para><para>
+ Second: look at the types of the things in scope.
+ GHCi has left its types parameterised by a variable!
+ Look at the type of <literal>qsort</literal>, which is
+ polymorphic on the type of its argument. It does not
+ tell us really what the types of <literal>x</literal> and <literal>xs</literal> can be.
+ In general, polymorphic programs deal with polymorphic values,
+ and this means that some of the bindings available in a breakpoint site
+ will be parametrically typed.
+ </para><para>
+ So, what can we do with a value without concrete type? Very few interesting
+ things. The <literal>:print</literal> command in ghci allows you to
+ explore its contents and see if it is evaluated or not.
+ This is useful because you cannot just type <literal>x</literal> in the
+ prompt and expect GHCi to return you its value. Perhaps you know for
+ sure that
+ <literal>x</literal> is of type <literal>Int</literal>, which is an instance of
+ <literal>Show</literal>, but GHCi does not have this information.
+ <literal>:print</literal> however is fine, because it does not need to know the
+ type to do its work. </para>
+ <para> Let's go on with the debugging session of the <literal>qsort</literal>
+ example:
+<example id="debuggingEx"><title>A short debugging session</title>
+<programlisting>
+qsort2.hs:2:15-46> x
+This is an untyped, unevaluated computation. You can use seq to
+force its evaluation and then :print to recover its type <co id="seq1"/>
+qsort2.hs:2:15-46> seq x () <co id="seq2"/>
+()
+qsort2.hs:2:15-46> x <co id="seq3"/>
+This is an untyped, unevaluated computation. You can use seq to
+force its evaluation and then :print to recover its type
+
+qsort2.hs:2:15-46> :t x
+x :: GHC.Base.Unknown
+qsort2.hs:2:15-46> :p x <co id="seq4"/>
+x - 10
+qsort2.hs:2:15-46> :t x <co id="seq5"/>
+x :: Int
+</programlisting>
+</example>
+ <calloutlist>
+ <callout arearefs="seq1">
+ <para>GHCi reminds us that this value is untyped, and instructs us to force its evaluation </para>
+ </callout>
+ <callout arearefs="seq2">
+ <para>This line forces the evaluation of <literal>x</literal> </para>
+ </callout>
+ <callout arearefs="seq3">
+ <para>Even though x has been evaluated, we cannot simply use its name to see its value!
+ This is a bit counterintuitive, but currently in GHCi the type of a binding
+ cannot be a type variable <literal>a</literal>.
+ Thus, the binding <literal>x</literal> gets assigned the concrete type Unknown.</para>
+ </callout>
+ <callout arearefs="seq4">
+ <para>We can explore <literal>x</literal> using the <literal>:print</literal>
+ command, which does find out that <literal>x</literal> is of type Int and prints
+ its value accordingly.</para>
+ </callout>
+ <callout arearefs="seq5">
+ <para><literal>:print</literal> also updates the type of <literal>x</literal> with
+ the most concrete type information available.</para>
+ </callout>
+ </calloutlist>
+ The example shows the standard way to proceeed with polymorphic values in a breakpoint.
+ </para>
+ </sect2>
+ <sect2><title>Commands</title>
+ <para>Breakpoints can be set in several ways using the <literal>:breakpoint</literal> command. Note that you can take advantage of the command abbreviation feature of GHCi and use simply <literal>:bre</literal> to save quite a few keystrokes.
+<variablelist>
+<varlistentry>
+ <term>
+ <literal>:breakpoint add <replaceable>module</replaceable> <replaceable>line</replaceable></literal>
+ </term>
+ <listitem><para>
+ Adds a breakpoint at the first event found at line <literal>line</literal> in <literal>module</literal>, if any.
+ </para></listitem>
+</varlistentry>
+<varlistentry>
+ <term>
+ <literal>:breakpoint add <replaceable>module</replaceable> <replaceable>line</replaceable> <replaceable>column</replaceable></literal>
+ </term>
+ <listitem><para>
+ Adds a breakpoint at the first event found after column <literal>column</literal>
+ at line <literal>line</literal> in <literal>module</literal>, if any.
+ </para></listitem>
+</varlistentry>
+
+<varlistentry>
+ <term>
+ <literal>:breakpoint continue</literal>
+ </term>
+ <listitem><para>
+ When at a breakpoint, continue execution up to the next breakpoint
+ or end of evaluation.
+ </para></listitem>
+</varlistentry>
+
+<varlistentry>
+ <term>
+ <literal>:continue</literal>
+ </term>
+ <listitem><para>
+ Shortcut for <literal>:breakpoint continue</literal>
+ </para></listitem>
+</varlistentry>
+
+<varlistentry>
+ <term>
+ <literal>:breakpoint list</literal>
+ </term>
+ <listitem><para>
+ Lists the currently set up breakpoints.
+ </para></listitem>
+</varlistentry>
+<varlistentry>
+ <term>
+ <literal>:breakpoint del <replaceable>num</replaceable></literal>
+ </term>
+ <listitem><para>
+ Deletes the breakpoint at position <literal>num</literal> in the list of
+ breakpoints shown by <literal>:breakpoint list</literal>.
+ </para></listitem>
+</varlistentry>
+<varlistentry>
+ <term>
+ <literal>:breakpoint del <replaceable>module</replaceable> <replaceable>line</replaceable></literal>
+ </term>
+ <listitem><para>
+ Dels the breakpoint at line <literal>line</literal> in <literal>module</literal>, if any.
+ </para></listitem>
+</varlistentry>
+<varlistentry>
+ <term>
+ <literal>:breakpoint del <replaceable>module</replaceable> <replaceable>line</replaceable><replaceable>col</replaceable> </literal>
+ </term>
+ <listitem><para>
+ Deletes the first breakpoint found after column <literal>column</literal>
+ at line <literal>line</literal> in <literal>module</literal>, if any.
+ </para></listitem>
+</varlistentry>
+<varlistentry>
+ <term>
+ <literal>:breakpoint stop </literal>
+ </term>
+ <listitem><para>
+ Stop the program being executed. This interrupts a debugging session
+ and returns to the top level.
+ </para></listitem>
+</varlistentry>
+</variablelist></para>
+ </sect2>
+ <sect2><title>Limitations</title>
+ <para>
+ <itemizedlist>
+ <listitem><para>
+ Implicit parameters (see <xref linkend="implicit-parameters"/>) are only available
+ at the scope of a breakpoint if there is a explicit type signature.
+ </para></listitem>
+ </itemizedlist>
+ <itemizedlist>
+ <listitem><para>
+ Modules compiled by GHCi under the <literal>-fdebugging
+ </literal> flag will perform slower: the debugging mode introduces some overhead.
+ Modules compiled to object code by ghc are not affected.
+ </para></listitem>
+ </itemizedlist>
+ </para>
+ </sect2>
+ <sect2><title>Tips</title>
+ <variablelist>
+ <varlistentry><term>* Use PRAGMAs to fine tune which modules are loaded under debugging mode</term>
+ <listitem>
+ <programlisting>{-# OPTIONS_GHC -fdebugging #-}</programlisting>
+ </listitem>
+ </varlistentry>
+ <varlistentry> <term>* Repeated use of <literal>seq</literal> and
+ <literal>:print</literal> may be necessary to observe unevaluated
+ untyped bindings</term>
+ <listitem><para>see <xref linkend="debuggingEx"/>
+ </para></listitem>
+ </varlistentry>
+ <varlistentry> <term> * <literal>GHC.Exts.unsafeCoerce</literal> can help if you are positive about the type of a binding</term>
+ <listitem><para><programlisting>
+type MyLongType a = [Maybe [Maybe a]]
+
+main:Main> :m +GHC.Exts
+main:Main> main
+Local bindings in scope:
+ x :: a
+Main.hs:15> let x' = unsafeCoerce x :: MyLongType Bool
+Main.hs:15> x'
+[Just [Just False, Just True]]
+ </programlisting>
+ Note that a wrong coercion will likely result in your debugging session being interrupted by a segmentation fault
+ </para></listitem>
+ </varlistentry>
+ <varlistentry> <term> * The undocumented (and unsupported) :force command </term>
+ <listitem><para>
+ equivalent to <literal> :print</literal> with automatic
+ <literal>seq</literal> forcing,
+ may prove useful to replace sequences of <literal>seq</literal> and
+ <literal>:print</literal> in some situations.
+ </para></listitem>
+ </varlistentry>
+ </variablelist>
+ </sect2></sect1>