CSL questions

Emmanuel Engel (Emmanuel.Engel@lri.fr)
Mon, 25 Sep 1995 12:01:55 +0100

Date: Mon, 25 Sep 1995 12:01:55 +0100
From: Emmanuel.Engel@lri.fr (Emmanuel Engel)
Message-Id: <199509251101.MAA00575@newsun8.lri.fr>
To: caml-list@pauillac.inria.fr
Subject: CSL questions

I have some (naives ?) questions about csl.

1) Why cslc and cslopt don't print part of the source
to explain where is error. The configuration found the
termlib, the toplevel (csltop) use it. It underline
error but cslc and cslopt juste write something like

(engel)newsun8 >cslc -c error.ml
File "error.ml", line 1, characters 12-16:
This expression has type bool but is here used with type int

camllight give a better indication of the location of the error.

>camlc -c error.ml
File "error.ml", line 1, characters 12-16:
>let v = 1 + true ;;
> ^^^^
This expression has type bool,
but is used with type int.

2) I have some problems with higher-order module
system. I try to define a type (camllight syntaxe)

type expr = V of int
| Binop of expr * expr
| A_op of expr list
| AC_op of expr set__t;;

So I write

**************** expr.ml *********************************

module type OrderedExpr = (* Set.OrderedType with t = expr *)
sig
type expr
val compare : expr -> expr -> int
end

module type SetExpr = (* Set.S with elt = expr *)
sig
type expr
type t
val empty : t
val is_empty : t -> bool
val mem : expr -> t -> bool
val add : expr -> t -> t
val remove : expr -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val iter : (expr -> 'a) -> t -> unit
val fold : (expr -> 'a -> 'a) -> t -> 'a -> 'a
val cardinal : t -> int
val elements : t -> expr list
val choose : t -> expr
end

module OrderedExpr =
struct
type expr = V of int
| Binop of expr * expr
| A_op of expr list
| AC_op of SetExpr.t

let compare = compare
end

module SetExpr:SetExpr = Set.Make((OrderedExpr:OrderedExpr))

*************************************************************

If i try to compile this I have

>cslc -c -i expr.ml
File "expr.ml", line 21, characters 23-37:
Unbound type constructor SetExpr.t

How can I recursivly define modules ? I need SetExpr to define
the type expr and I need the type expr to define SetExpr.

3) If I suppress the case AC_op in my definition I still have some problems.

>cslc -c -i expr.ml
File "expr.ml", line 47, characters 34-60:
Signature mismatch:
Modules do not match: OrderedExpr is not included in Set.OrderedType
The field `t' is required but not provided

So I try to use the "with" constuct

My first try was not good

module SetExpr:SetExpr =
Set.Make(((OrderedExpr:OrderedExpr):Set.OrderedType with t=OrderedExpr.expr))

>cslc -c -i expr.ml
File "expr.ml", line 48, characters 35-60:
Signature mismatch:
Modules do not match:
OrderedExpr
is not included in
sig type t = OrderedExpr.expr val compare : t -> t -> int end
The field `t' is required but not provided

The second one too

module SetExpr:SetExpr =
Set.Make((OrderedExpr:Set.OrderedType with t=OrderedExpr.expr))

>cslc -c -i expr.ml
File "expr.ml", line 52, characters 35-46:
Signature mismatch:
Modules do not match:
sig
type expr = V of int | Binop of expr * expr | A_op of expr list
val compare : expr -> expr -> int
end
is not included in
sig type t = OrderedExpr.expr val compare : t -> t -> int end
The field `t' is required but not provided

Emmanuel Engel