Шаги сокращения представления в Haskell

Я смог понять это достаточно, чтобы двигаться дальше. После некоторых экспериментов я добавил следующую строку.

pieSeries.format.gradient.stops=[0,0.15];
14
задан Chris Martin 21 March 2016 в 10:19
поделиться

4 ответа

You could try inserting Debug.Trace.trace in places you want to trace, but this has the tendency of (a) producing wildly out-of-order output, as your trace statement may belong to a thunk that isn't evaluated until far far away from the original call, and (b) changing the runtime behavior of your program, if tracing requires evaluating things that wouldn't otherwise have been evaluated (yet).

Is this for debugging? If so...


Hat modifies your source code to output tracing which can be viewed after running. The output should be pretty close to what you want: the example on their homepage is

For example, the computation of the faulty program

main = let xs :: [Int]
 xs = [4*2,5 `div` 0,5+6]
 in print (head xs,last' xs)

last' (x:xs) = last' xs
last' [x] = x

gives the result

(8, No match in pattern.

and the Hat viewing tools can be used to explore its behaviour as follows:

  • Hat-stack

For aborted computations, that is computations that terminated with an error message or were interrupted, hat-stack shows in which function call the computation was aborted. It does so by showing a virtual stack of function calls (redexes). Thus, every function call shown on the stack caused the function call above it. The evaluation of the top stack element caused the error (or during its evaluation the computation was interrupted). The stack shown is virtual, because it does not correspond to the actual runtime stack. The actual runtime stack enables lazy evaluation whereas the virtual stack corresponds to a stack that would be used for eager (strict) evaluation.

Using the same example program as above, hat-stack shows

$ hat-stack Example
Program terminated with error:
 No match in pattern.
Virtual stack trace:
(Last.hs:6) last' []
(Last.hs:6) last' [_]
(Last.hs:6) last' [_,_]
(Last.hs:4) last' [8,_,_]
(unknown) main
$

These days, GHCi (≥6.8.1) also comes with a debugger:

$ ghci -fbreak-on-exception
GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> :l Example.hs
[1 of 1] Compiling Main             ( Example.hs, interpreted )

Example.hs:5:0:
    Warning: Pattern match(es) are overlapped
             In the definition of `last'': last' [x] = ...
Ok, modules loaded: Main.
*Main> :trace main
(8,Stopped at <exception thrown>
_exception :: e = _
[<exception thrown>] *Main> :back
Logged breakpoint at Example.hs:(5,0)-(6,12)
_result :: t
[-1: Example.hs:(5,0)-(6,12)] *Main> :hist
-1  : last' (Example.hs:(5,0)-(6,12))
-2  : last' (Example.hs:5:15-22)
-3  : last' (Example.hs:(5,0)-(6,12))
-4  : last' (Example.hs:5:15-22)
-5  : last' (Example.hs:(5,0)-(6,12))
-6  : last' (Example.hs:5:15-22)
-7  : last' (Example.hs:(5,0)-(6,12))
-8  : main (Example.hs:3:25-32)
-9  : main (Example.hs:2:17-19)
-10 : main (Example.hs:2:16-34)
-11 : main (Example.hs:3:17-23)
-12 : main (Example.hs:3:10-33)
<end of history>
[-1: Example.hs:(5,0)-(6,12)] *Main> :force _result
*** Exception: Example.hs:(5,0)-(6,12): Non-exhaustive patterns in function last'

[-1: Example.hs:(5,0)-(6,12)] *Main> :back
Logged breakpoint at Example.hs:5:15-22
_result :: t
xs :: [t]
[-2: Example.hs:5:15-22] *Main> :force xs
xs = []

While not as nice, it has the benefit of being easily available, and being usable without recompiling your code.

7
ответ дан 1 December 2019 в 16:24
поделиться

There's a reduction count in hugs, if that helps? Alternatively, could you use something like the hugs hood to wrap your code, to get more detail around what it's doing at each step?

0
ответ дан 1 December 2019 в 16:24
поделиться

Ничего подобного не встроено в стандарт Haskell.

Я надеюсь, что графический интерпретатор Helium предложит что-то подобное, но веб-страница молчит по теме.

0
ответ дан 1 December 2019 в 16:24
поделиться

Частичным решением является использование вакуума для визуализации структур данных.

Я видел некоторые gif-анимации свертывания, сканирования и других, но я не могу найти их в данный момент. Я думаю, что Кейл Гиббард сделал анимацию.

0
ответ дан 1 December 2019 в 16:24
поделиться
Другие вопросы по тегам:

Похожие вопросы: