* CSL questions
@ 1995-09-25 11:01 Emmanuel Engel
1995-09-28 15:28 ` Xavier Leroy
0 siblings, 1 reply; 2+ messages in thread
From: Emmanuel Engel @ 1995-09-25 11:01 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: CSL questions
1995-09-25 11:01 CSL questions Emmanuel Engel
@ 1995-09-28 15:28 ` Xavier Leroy
0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 1995-09-28 15:28 UTC (permalink / raw)
To: Emmanuel Engel; +Cc: caml-list
> 1) Why cslc and cslopt don't print part of the source
> to explain where is error.
Correct. I finally noticed that during batch compilation it's
basically useless to print source fragments with the errors
underlined: since you're compiling from a file, you'll have to open it
with an editor and go to the line with the error anyway; you'll locate
the error inside the editor, not on the output of the compiler.
For Emacs users, the best solution is still to compile under Emacs
with M-x compile, then use find-next-error to jump to the error
location.
> How can I recursivly define modules ? I need SetExpr to define
> the type expr and I need the type expr to define SetExpr.
You can't. That's one of the most annoying restrictions of SML-style
module systems. Unfortunately, compiling mutually recursive module
definitions is hard. Some workarounds are described in the user's
manual (chapter "Batch compilation", section "Common errors". I'm
afraid they won't apply in your example, though.
> 3) If I suppress the case AC_op in my definition I still have some problems.
The Set.Make functor requires a type named "t" in its argument; just
provide it:
type expr = V of int
| Binop of expr * expr
| A_op of expr list
module SetExpr =
Set.Make(struct type t = expr let compare = compare end)
By the way, there's no need to write all these signature constraints
by hand, the system will do the right thing if you don't put them;
moreover, over-constraining may cause some types to become abstract
when you don't want them to.
> So I try to use the "with" constuct
There is a misunderstanding here: "with" does not rename type fields,
it adds an equality over an existing type field. So if S is
sig type t ... end
then S with t = expr is
sig type t=expr ... end
but not
sig type expr ... end
- Xavier Leroy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1995-09-29 8:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-09-25 11:01 CSL questions Emmanuel Engel
1995-09-28 15:28 ` Xavier Leroy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox