Forlan Manual

The 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
returns the function that, when called with (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.

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 =
         ("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));

[ Top | Parent | Root | Contents | Index ]

Forlan Version 4.12
Copyright © 2019 Alley Stoughton