[clean-list] declaration order

Arjen van Weelden A.vanWeelden at cs.ru.nl
Wed Jan 3 10:25:34 MET 2007


Jigang Sun wrote:
> I observed that unlike traditional language, Clean does not care declaration order, for example 
> 
> //Start module
> module try
> import StdEnv
> instance plus Int
> where
>  ( plus ) x y = x + y  
> 
> class (plus) infixl 6 a :: !a !a -> a		
> 
> Start =  1 plus 3
> produces 4 without complaining. 
> 
> In the example, type class instance is declared before type class.
> 
> If this were an imperative language, the compiler should complie in contextual order, i.e. compile type class declaration first and store the result somewhere, when meet type class instance declaration lately, read the type class information and create an type class instance. I wonder if this is a common feature of functional language. 
> 
> Thanks.
> Jigang
> 
Mutual recursive functions are common in functional programs. Also, 
where and let(rec) clauses are often mutual dependent. I think that 
because of this, most compilers of functional languages are multi-pass 
and do not require a function's specification before it's used. It seems 
natural to extend this to all kinds of declarations.

For example: imports can appear anywhere in a Clean module and the 
imported functions can be used everywhere in the module. I would not be 
surprised if other functional languages are similar. Although, I know 
that imports in Haskell are required at the beginning of a module.

To me, it appears that functional languages do not care about 
declaration order in general. Except that some of them do require 
certain kinds of declarations before their use, and they disagree about 
to which kind of declarations this applies.

regards,
	Arjen


More information about the clean-list mailing list