# Difference between revisions of "Hoed"

(a short summary of Hoed, more to come ...) |
(using Hoed) |
||

Line 1: | Line 1: | ||

− | Hoed is a lightweight algorithmic debugger that is practical to use for real-world programs |
+ | Hoed is a lightweight tracer and algorithmic debugger that is practical to use for real-world programs. |

+ | |||

+ | == Using Hoed == |
||

To locate a defect with Hoed you annotate suspected functions and compile as usual. Then you run your program, information about the annotated functions is collected. Finally you connect to a debugging session using a webbrowser. |
To locate a defect with Hoed you annotate suspected functions and compile as usual. Then you run your program, information about the annotated functions is collected. Finally you connect to a debugging session using a webbrowser. |
||

+ | |||

+ | Let us consider the following program, a defective implementation of a parity function with a test property. |
||

+ | |||

+ | <pre> |
||

+ | isOdd :: Int -> Bool |
||

+ | isOdd n = isEven (plusOne n) |
||

+ | |||

+ | isEven :: Int -> Bool |
||

+ | isEven n = mod2 n == 0 |
||

+ | |||

+ | plusOne :: Int -> Int |
||

+ | plusOne n = n + 1 |
||

+ | |||

+ | mod2 :: Int -> Int |
||

+ | mod2 n = div n 2 |
||

+ | |||

+ | prop_isOdd :: Int -> Bool |
||

+ | prop_isOdd x = isOdd (2*x+1) |
||

+ | </pre> |
||

+ | |||

+ | |||

+ | Using the property-based test tool QuickCheck we find the counter example 1 for our property. |
||

+ | |||

+ | <pre> |
||

+ | > quickCheck prop_isOdd |
||

+ | *** Failed! Falsifiable (after 1 test): 1 |
||

+ | </pre> |
||

+ | |||

+ | Hoed can help us determine which function is defective. We annotate the functions isOdd, isEven, plusOne and mod2 as follows: |
||

+ | |||

+ | <pre> |
||

+ | import Debug.Hoed.Pure |
||

+ | |||

+ | isOdd :: Int -> Bool |
||

+ | isOdd = observe "isOdd" isOdd' |
||

+ | isOdd' n = isEven (plusOne n) |
||

+ | |||

+ | isEven :: Int -> Bool |
||

+ | isEven = observe "isEven" isEven' |
||

+ | isEven' n = mod2 n == 0 |
||

+ | |||

+ | plusOne :: Int -> Int |
||

+ | plusOne = observe "plusOne" plusOne' |
||

+ | plusOne' n = n + 1 |
||

+ | |||

+ | mod2 :: Int -> Int |
||

+ | mod2 = observe "mod2" mod2' |
||

+ | mod2' n = div n 2 |
||

+ | |||

+ | prop_isOdd :: Int -> Bool |
||

+ | prop_isOdd x = isOdd (2*x+1) |
||

+ | </pre> |
||

+ | |||

+ | Now we use the combinator testO to trace our program for the count-example of our property. |
||

+ | After running the program a computation tree is constructed and displayed in a web browser. |
||

+ | |||

+ | |||

+ | <pre> |
||

+ | > testO prop_isOdd 1 |
||

+ | *** Failed! Falsifiable: 1 |
||

+ | Listening on http://127.0.0.1:10000/ |
||

+ | </pre> |
||

+ | |||

+ | |||

+ | You can freely browse this tree to get a better understanding of your program. If your program misbehaves, you can judge the computation statements in the tree as 'right' or 'wrong' according to your intention. When enough statements are judged the debugger tells you the location of the fault in your code. |
||

+ | |||

+ | == Other Tracers and Debuggers == |
||

+ | |||

+ | With Hoed trusted libraries do not need to be be transformed and is therefore |

## Revision as of 11:46, 23 November 2015

Hoed is a lightweight tracer and algorithmic debugger that is practical to use for real-world programs.

## Using Hoed

To locate a defect with Hoed you annotate suspected functions and compile as usual. Then you run your program, information about the annotated functions is collected. Finally you connect to a debugging session using a webbrowser.

Let us consider the following program, a defective implementation of a parity function with a test property.

isOdd :: Int -> Bool isOdd n = isEven (plusOne n) isEven :: Int -> Bool isEven n = mod2 n == 0 plusOne :: Int -> Int plusOne n = n + 1 mod2 :: Int -> Int mod2 n = div n 2 prop_isOdd :: Int -> Bool prop_isOdd x = isOdd (2*x+1)

Using the property-based test tool QuickCheck we find the counter example 1 for our property.

> quickCheck prop_isOdd *** Failed! Falsifiable (after 1 test): 1

Hoed can help us determine which function is defective. We annotate the functions isOdd, isEven, plusOne and mod2 as follows:

import Debug.Hoed.Pure isOdd :: Int -> Bool isOdd = observe "isOdd" isOdd' isOdd' n = isEven (plusOne n) isEven :: Int -> Bool isEven = observe "isEven" isEven' isEven' n = mod2 n == 0 plusOne :: Int -> Int plusOne = observe "plusOne" plusOne' plusOne' n = n + 1 mod2 :: Int -> Int mod2 = observe "mod2" mod2' mod2' n = div n 2 prop_isOdd :: Int -> Bool prop_isOdd x = isOdd (2*x+1)

Now we use the combinator testO to trace our program for the count-example of our property. After running the program a computation tree is constructed and displayed in a web browser.

> testO prop_isOdd 1 *** Failed! Falsifiable: 1 Listening on http://127.0.0.1:10000/

You can freely browse this tree to get a better understanding of your program. If your program misbehaves, you can judge the computation statements in the tree as 'right' or 'wrong' according to your intention. When enough statements are judged the debugger tells you the location of the fault in your code.

## Other Tracers and Debuggers

With Hoed trusted libraries do not need to be be transformed and is therefore