[Haskell-cafe] getting the name of a function for test diagnostic purposes

Terrence Brannon bauhaus at metaperl.com
Thu Mar 3 08:28:12 EST 2005

I have written a program (below) to run a test suite for a list of functions:

    [isTotalJunc, isPartialJunc]

where each function receives a datum of type ApplyArg whose value slot is 
one element at a time of the list of types below:

    [JNone, JOne, JAny, JAll] 

I therefore must run 8 tests (the cross product of functions and types).

Right now, here is the output:

*Main> test_total_partial
["fun: (->)input: JNoneoutput: True","fun: (->)input: JOneoutput: False","fun: (->)input: JAnyoutput: False","fun: (->)input: JAlloutput: True","fun: (->)input: JNoneoutput: False","fun: (->)input: JOneoutput: True","fun: (->)input: JAnyoutput: True","fun: (->)input: JAlloutput: False"]

  -- One problem is that functions do not print as their name. The
     call to (show f) in showres simply yields (->)

  -- Another problem is that I cannot manage to separate each string
     with a carriage return.

Any help with these problems is appreciated.


test_total_partial = let funs  = [isTotalJunc, isPartialJunc]
			 types = [JNone, JOne, JAny, JAll] 
			 mkdat typ = ApplyArg "somename" (VJunc $ Junc typ emptySet emptySet) False
		         showres f t r = "fun: " ++ (show f) ++ "input: " ++ (show t) ++ "output: " ++ (show r)
		         runtest f t = do {
					   retval <- f (mkdat t);
					   return $ (showres f t retval)
  [ (showres f t (f (mkdat t))) | f <- funs, t <- types ]

	Carter's Compass: I know I'm on the right track when,
	   by deleting something, I'm adding functionality.

More information about the Haskell-Cafe mailing list