Trying to get a NN code going

Gert Veldhuijzen van Zanten veldhvz@ipo.tue.nl
Fri, 26 Feb 1999 09:59:41 +0100


Hi Richard,

> What do UNIX Clean programmers do when they get a segmentation
> violation?  How do I track this down to its cause?

Well, firstly I panic. Or I look over the portion of the code that I
just changed, fiddle around with it. 

> This is the first Clean program I've had where the compiler hasn't
> told me about all the bugs, and I'm wondering how other Clean
> programmers go about debugging their code.  In SML, I'd just whack in
> a few print commands and be away laughing.

When examaning the code and fiddling around doesn't work. Or when I have
some clue where to look, then I add some trace calls; 
define a function

	trace :: !String x -> x
	trace s x
	    #! y    = fwrites (s+++"\n") stderr
	    | 2 > 1 = K x y
	    = abort "?"
	where
	    K x y = x 

This is some wizardry the Clean team dreamt up.
But with it you can 'whack in a few print commands'

Eg. you suspect some function f 
	f :: X Y -> Z
	f x y 
	   | x > y     = f (x-1) y
	   | otherwise = x + y

I often change this to something like

	f :: X Y -> Z
	f x y = trace ("f "+++(toString x)+++" "+++(toString y)) f` x y

	f` x y 
	   | x > y     = f (x-1) y
	   | otherwise = x + y

Doing it this way usually causes the trace strings to be printed before
the function application is evaluated. If you want to also know the
result of a call, then write:

	f :: X Y -> Z
	f x y 
	    = trace (fn+++" = "+++(toString z)) z
	where
	    fn = "f "+++(toString x)+++" "+++(toString y)
	    z  = trace fn f` x y

	f` x y 
	   | x > y     = f (x-1) y
	   | otherwise = x + y

Unfortunately, this means that I usually have to write toString 
instances of all the types that I use. I am still hoping for the Clean
team to make available at some time the functions that print the Start
expression to the console.

Greetings
-- 
Gert Veldhuijzen van Zanten      P.O. Box 513, NL-5600 MB  Eindhoven
 ____________________________    +31 40 2475260, fax: +31 40 2431930
| IPO, Center for Research   |                    veldhvz@ipo.tue.nl
|_on User-System Interaction_|  http://www.tue.nl/ipo/people/veldhvz