Presumably this means differentiation/integeration would have to be typed as

diff :: (FnExt a,FnExt b) => a -> b

Chris


> -----Original Message-----
> From: Peter Achten [mailto:[EMAIL PROTECTED]]
> Sent: 25 September 2000 23:34
> To: Jose Romildo Malaquias
> Cc: [EMAIL PROTECTED]
> Subject: Re: Extensible data types?
> 
> 
> At 07:46 25-9-00 -0300, Prof. José Romildo Malaquias wrote:
> 
> >Hello.
> >
> >Is there any Haskell implementation that supports
> >extensible data types, in which new value constructors
> >can be added to a previously declared data type,
> >like
> >
> >         data Fn = Sum | Pro | Pow
> >         ...
> >         extend data Fn = Sin | Cos | Tan
> >
> >where first the Fn datatype had only three values,
> >(Sum, Pro and Pow) but later it was extended with
> >three new values (Sin, Cos and Tan)?
> >
> >What are the pointers to documentation on such
> >kind of extensions to Haskell?
> 
> In the Clean Object I/O library we encountered a similar 
> challenge and 
> solved it using type constructor classes. The solution can 
> also be used in 
> Haskell. The basic idea is as follows:
> 
> (1) For each type constructor that has to be extensible you 
> introduce a 
> type constructor class;
> (2) For each of the data constructors of such type constructors you 
> introduce a new type constructor (reusing their name is very 
> convenient);
> (3) For each such new type constructor define it as an 
> instance of the type 
> constructor class that was created from its parent type constructor.
> 
> Example:
> 
> (1) From type constructor Fn you create:
> class FnExt where
>      ...   -- Define your class member functions here
> 
> (2) From the data constructors Sum | Pro | Pow you create:
> data Sum = Sum
> data Pro  = Pro
> data Pow  = Pow
> 
> (3) For each newly defined type constructor in (2) you define 
> an instance:
> instance FnExt Sum
> instance FnExt Pro
> instance FnExt Pow
> 
> 
> All of your functions that previously were defined on Fn are 
> now overloaded 
> functions:
> 
> fun :: ... Fn ... -> ... Fn ...
> 
> becomes:
> 
> fun :: (FnExt fn) => ... fn ... -> ... fn ...
> 
> I hope you find this scheme useful. I guess its applicability 
> depends on 
> your particular class member functions and program.
> 
> Regards,
> Peter Achten
> 
> =========================
> References: although the perspective in the Clean Object I/O 
> library is on 
> the data structures with generic interpretation functions, 
> the technique is 
> basically the same as described here.
> 
> In my PhD Thesis you can find an early reference:
> * The reference:
> Achten, P.M. Interactive Functional Programs - Models, Methods, and 
> Implementation. PhD thesis, University of Nijmegen, 1996.
> * The abstract at:
> http://www.cs.kun.nl/~peter88/PeterThesisCh6.html
> * The chapter at:
> ftp://ftp.cs.kun.nl/pub/CSI/SoftwEng.FunctLang/papers/achp96-t
hesis6.ps.gz

A more modern version can be found here:
* The reference:
Achten, P.M. and Plasmeijer, M.J. Interactive Functional Objects in Clean. 
In Clack, C., Hammond, K., and Davie, T. eds., Proceedings 9th 
International Workshop Implementation of Functional Languages, IFL'97, 
St.Andrews, Scotland, UK, September 1997, selected papers, LNCS 1467, 
Springer, pp. 304-321.
* The abstract at:
ftp://ftp.cs.kun.nl/pub/Clean/papers/1998/achp97-InteractFuncObjects.abs
* The paper at:
ftp://ftp.cs.kun.nl/pub/Clean/papers/1998/achp97-InteractFuncObjects.ps.gz


Reply via email to