Version française
Home     About     Download     Resources     Contact us    
Browse thread
compilation of lablgl examples.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pierre Weis <Pierre.Weis@i...>
Subject: Re: compilation of lablgl examples.
> > Could you explain a bit why ``the use of standard variant
> > constructors is extremely heavy'' (I thought it was on the contrary
> > extremely light and elegant!) ?
> 
> 	Excuse my poor English -- what I meant was
> "A very large percentage of symbols in the source code
> are variant constructor names". A very large amount of code
> consists of match .. with statements where the expression
> is a variant type, and the result expressions are another
> variant. 

May be it is my understanding of English which is bad, not your way to
write it :(

> 	For example, something like this happens:
> the type of a function declaration in the Abstract Syntax Tree is:
> 
>   | AST_function of id_t * parameter_t list * typecode_t * statement_t
> list
> 
> which is converted to:
>  
>   | DCL_function of   parameter_t list * typecode_t * asm_t list
> 
> which is converted to:
> 
>   | SYMDEF_function of parameter_t list * typecode_t * int list * exe_t
> list * name_map_t
>  
> which is converted to:
> 
>   | BDCL_function of   bparameter_t list * btypecode_t * int list *
> exe_t list * name_map_t
> 
> which is converted to:
> 
>   | BBDCL_function of   bparameter_t list * btypecode_t * int list *
> bexe_t list * name_map_t

This is very often considered good practice. However, I agree with you
that is can be heavy to code. Sometimes you can use polymorphism to
help for instance defining

| Function of 'parameter list * typecode_t * 'b

could be used to modelize both
| DCL_function of   parameter_t list * typecode_t * asm_t list
| BDCL_function of   bparameter_t list * btypecode_t * int list *
 exe_t list * name_map_t

and similarly

| Bfunction of 'parameter list * btypecode_t * int list * 'exe list *
name_map_t

coulod serve for:
| BDCL_function of   bparameter_t list * btypecode_t * int list * exe_t list * name_map_t
and
| BBDCL_function of   bparameter_t list * btypecode_t * int list * bexe_t list * name_map_t

This does not jeopardize static typing and lowers the needs for type
declarations ...

[...]
> I.e., polymorphic variants are more useful for prototyping,
> since types do not need to be declared before writing
> algorithms, yet the declarations can still be added later
> when the design is solider to check just how solid it really is.

This is an interesting idea, worth a try. I'm still not sure the
static type checker could handle gracefully the ``partial and
exhaustive match'' problem, but I may be wrong...

[...]
You should try on a small example, not on a huge optimizing compiler
for a full fledged language!

Best regards,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/