Debug
Module
signature DEBUG
structure Debug
:> DEBUG
This module contains a function for debugging Forlan code.
val debug : ('a -> PP.pp) -> PP.pp * 'a -> 'a
debug h
(msgPP,
x)
, prints on the standard output PP.toString
msgPP
, followed by a colon, followed by PP.toString(h x)
, followed by a newline, followed by "(press RETURN to continue or interrupt character to interrupt)
"
; it then waits for user input; if the user responds by typing RETURN, then the function will return x
.
Example:
We can instrument the factorial function
fun fact n = if n = 0 then 1 else n * fact(n - 1);for debugging as follows:val debugInt = Debug.debug(PP.fromString o Int.toString); fun fact n = debugInt (PP.fromString ("returning from fact " ^ Int.toString n ^ " with result"), if debugInt(PP.fromString "entering fact with argument", n) = 0 then 1 else n * fact(n - 1));
Forlan Version 4.15
Copyright © 2022 Alley Stoughton