Version franēaise
Home     About     Download     Resources     Contact us    
Browse thread
Compiler feature - useful or not?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Edgar Friendly <thelema314@g...>
Subject: Re: [Caml-list] Compiler feature - useful or not?
Jacques Garrigue wrote:
> This syntax could be nice, but it is just syntactic sugar for
> 
> module Private_row : sig
>   type row = private int
>   val new_row : int -> row
> end = struct
>   type row = int
>   let new_row i = assert (i >= 0); i
> end
> include Private_row
> 
Funny to define a module (hiding) just to include it (un-hiding).  This
pair usually comes to a no-op, but here it doesn't.

> I'm sure camlp4 can do that.
> 
It can.  But camlp4 holds back real development of the OCaml Community
by dividing the language into incompatible splinter dialects or forcing
us to code in pure OCaml which has little sugar.

> Direct compiler support couldn't give you more:
> 
> * you cannot use a coercion to create a row: coercions are purely
>   type-level features, and cannot execute any code; we don't want to
>   change this. On the other hand coercing row to int could be made ok.
> 
Good point.  And I guess there's no better way to pack the creation
assertion with the type than a module with a constructor function...

> * the "constraint ..." part cannot appear in an interface, since
>   interfaces cannot contain expressions
> 
Having interfaces contain arbitrary expressions...  difficult.  But I
guess that we would have a 90% solution by reducing the problem from
arbitrary constraints to simple range constraints.  As long as it worked
for ints, floats and chars, ....  Still not trivial, though.

Kila la heri,
E.