recursive modules in Haskell
Hi all! I've just got one of the rare chances to do a somewhat bigger piece of software development in Haskell. After having set up a design (with much use of multi-parameter-classes) I was very excited. However, to extent that implementation proceeded I had to recognize many unforeseen implementation dependencies between instance. A standard situation is: file A.hs: instance Foo A f :: -- implementation requires A and B to be an instance of Foo file B.hs: instance Foo B f :: -- implementation requires A and B to be an instance of Foo The mutual dependencies increase if one uses class constraints to enforce semantic wellformedness, that is if one writes given Bar A => class Foo A whenever this makes sense from the view of the application logic - as I did. No Problem at all for Haskell, but a problem for certain often-used Haskell compilers and interpreters... Factoring out "the common part" does not work in examples like above, so the only way is to collapse everything, and to reduce class constraints as much as is possible - something which hurts deep inside! That the problems appear step-by-step in the course of implementation or even debugging, adds to the pain. So I have put onto my personal Haskell whish-list that certain compilers and interpreters shall either ultimately converged against the language they intend to support, or else provide some suitable alternative. Thinking in the first direction, a precompiler appears before my inner eye which is able to collapse mutually dependent modules into one bigger module. Even if this led to incorrect line numbers in error messages and the like, I would definitely use such a precompiler. A step in the second direction was a slight modification of Haskell such that instance declaration and instance implementation can be provided in separate modules. Elke. -- Elke Kasimir EsPresto AG ----------------------------------------------------------------- - Software Development- Breite Str. 30-31 Tel/Fax: +49-30-90 226-750/-760 10178 Berlin/Germany
hi, Elke Kasimir wrote:
No Problem at all for Haskell, but a problem for certain often-used Haskell compilers and interpreters...
Factoring out "the common part" does not work in examples like above, so the only way is to collapse everything, and to reduce class constraints as much as is possible - something which hurts deep inside! That the problems appear step-by-step in the course of implementation or even debugging, adds to the pain.
So I have put onto my personal Haskell whish-list that certain compilers and interpreters shall either ultimately converged against the language they intend to support, or else provide some suitable alternative. Thinking in the first direction, a precompiler appears before my inner eye which is able to collapse mutually dependent modules into one bigger module. Even if this led to incorrect line numbers in error messages and the like, I would definitely use such a precompiler. A step in the second direction was a slight modification of Haskell such that instance declaration and instance implementation can be provided in separate modules.
there is no need to use such hacks. it is not dificult to add suport for mutually recursive modules to an implementation directly. unfortunatley none of the working haskell implementations support recursive modules, i guess they are probably not considered important enough. and the haskell report does not say how they should work (ergh why?), but if you are interested you can take a look at "A formal specification for the Haskel 98 module system" a paper we wrote to remedy this situation. in the mean time you can work around the problem in GHC, by using the hi-boot files take a look at the documentation "How to compile mutually recursive modules". bye iavor -- ================================================== | Iavor S. Diatchki, Ph.D. student | | Department of Computer Science and Engineering | | School of OGI at OHSU | | http://www.cse.ogi.edu/~diatchki | ==================================================
participants (2)
-
Elke Kasimir -
Iavor S. Diatchki