24.3 Creating your Own Functors

Of couse, there is also new syntax in Mozart for describing functors. Consider for instance the following functor definition:

<NewChart.oz>=
functor  
import  
   Browser
   System
export  
   NewChart
define 
   Browse = Browser.browse
   Show = System.show
   %% something reasonable has to be put here
   fun {NewChartunit end  
   {Browse 'function NewChart computed'}
   {Show 'function NewChart computed'}
end

Suppose that the content of the chunk NewChart.oz is stored in a file that is also called NewChart.oz. Then you can compile the functors definition in this file calling the Oz complile within you shell. This can be done by executing the following shell command:

ozc -c NewChart.oz -o NewChart.ozf

The shortcut ozc stand for Oz compiler. The option -c NewChart.oz means that the compiler is asked to compile the functor definition in the file NewChart.oz. The output option -o NewChart.ozf requires that the functor obtained is stored in the file NewChart.ozf. The output option can be omitted. In this case, a default file name is used storing the functor. The default name is computed from the input file name by replacing the suffix .oz by .ozf.


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)