functions with states

Fergus Henderson fjh@cs.mu.oz.au
Sat, 6 May 2000 19:42:32 +1000


On 06-May-2000, khamenya <khamenya@module.ru> wrote:
> //============start of model project
> 
> // ------------------low level of my project:
> foo::Int Int ->Int
> foo x y = x+y
> 
> //------------------medium level of my project:
> fib::Int ->Int
> fib 1 = 1
> fib 2 = 1
> fib x = foo (fib (x-1)) (fib (x-2))
> 
> //----------------- high lveel (driver) of my project:
> Start = foldl foo 0 (map fib [1..6])
> //================== end of medel project
> 
> Here it is a naive model project I manage.
> What do I need when the CUSTOMER says "well! everything is all
> right!... but I also need a typical history of your 'foo' function.
> Why?.. you said it is most expensive function i'd like to learn its
> specific and improve my hardware for it."
> 
> [It is normal. And here no matter that 'fib' is not optimised enough!]
> What should I have? All modules are debuged enough and I need only a
> small modification dealing with low level function 'foo'. I notice that
> Clean is touchy for such a modification. Type system which usualy
> helps us now stops us.
> 
> Of cours the logging affects the 'world' environment. But the history
> logging is not a "side effect" in its algorithmic essence.  Potentially
> this history logging might be implemented in functional languages
> style. Can we do such a small addition in Clean? inoffensively?

I don't know if there is any easy way of doing it in Clean.

But if you wanted to do the same thing for Mercury, which is in
many ways very similar to Clean, there is now a tool available
which makes it quite easy.  This tool is a trace analysis system
called "Morphine".  From the Mercury web site:

 | [19 Jan 2000] Morphine released
 | Morphine, a trace analysis system for Mercury, has just been added to
 | the Mercury distribution (and will be available in Mercury 0.9.1).
 | Morphine allows dynamic tracing of Mercury programs, allowing scripts
 | to be written which interact with the debugger and efficient
 | collection of statistics on running programs. Many thanks to Erwan
 | Jahier for his hard work on Morphine.

Rather than modifying your original program, you would just compile it
with debugging enabled, run it under the Morphine debugger, and then
use a short Morphine command (or some Mercury code) to extract the
information that you need from the complete program execution trace.

For more information on Morphine, see
<http://www.irisa.fr/lande/jahier/download.html>.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3        |     -- the last words of T. S. Garp.