* Rebinding exception declarations @ 1999-10-13 16:59 Manuel Fahndrich 1999-10-14 22:52 ` skaller 0 siblings, 1 reply; 5+ messages in thread From: Manuel Fahndrich @ 1999-10-13 16:59 UTC (permalink / raw) To: 'caml-list@inria.fr' While we are at wishing for new features in OCaml, let me add a minor feature to the list: Rebinding of exception declarations. Currently, in OCAML I cannot do the following: module A = struct exception E end module B = struct exception E = exception A.E end In order to have an exception declaration in a module, it must syntactically appear there. That prevents me from repackaging my modules in a different way for the programmer interface. The only way around it is currently to define a brand new exception and wrap all interface functions with a handler that translates A.E into B.E. One argument against providing such exception rebinding is that it introduces aliasing between exception constructors. However, OCAML already has that problem now through functors. Consider: module type Argsig = sig module X : sig exception E end module Y : sig exception E end end module F = functor(Arg : Argsig) -> struct try ... with Arg.X.E -> ... | Arg.Y.E -> ... end module A = struct exception E end module Z = F(struct module X = A module Y = A end) Within Z, exceptions Arg.X.E and Arg.Y.E are aliased. -Manuel P.S. Exception rebinding is standard in SML. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Rebinding exception declarations 1999-10-13 16:59 Rebinding exception declarations Manuel Fahndrich @ 1999-10-14 22:52 ` skaller 1999-10-15 7:12 ` Pierre Weis 1999-10-17 14:22 ` Xavier Leroy 0 siblings, 2 replies; 5+ messages in thread From: skaller @ 1999-10-14 22:52 UTC (permalink / raw) To: Manuel Fahndrich; +Cc: 'caml-list@inria.fr' Manuel Fahndrich wrote: > > While we are at wishing for new features in OCaml, let me add a minor > feature to the list: > > Rebinding of exception declarations. Actually, I think there is a more syntactic problem: ocaml uses special 'kinds' of bindings, for some reason that escapes me: type X = .. class X = .. exception .. let X = .. let rec X = module X = which permit recursion with an 'and' option. Unfortunately, this syntax does not permit these kinds of bindings to be mutually recursive (quite aside from the semantic issues). I find this syntax strange, I would have expected let X = be enough for all kinds of bindings, determined by the kind of the right hand side. The distinction between sequential and recursive bindings for functions seems anomolous [let .. in can be used for that]. -- John Skaller, mailto:skaller@maxtal.com.au 1/10 Toxteth Rd Glebe NSW 2037 Australia homepage: http://www.maxtal.com.au/~skaller downloads: http://www.triode.net.au/~skaller ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Rebinding exception declarations 1999-10-14 22:52 ` skaller @ 1999-10-15 7:12 ` Pierre Weis 1999-10-17 11:15 ` skaller 1999-10-17 14:22 ` Xavier Leroy 1 sibling, 1 reply; 5+ messages in thread From: Pierre Weis @ 1999-10-15 7:12 UTC (permalink / raw) To: skaller; +Cc: caml-list > Manuel Fahndrich wrote: > > > > While we are at wishing for new features in OCaml, let me add a minor > > feature to the list: > > > > Rebinding of exception declarations. > > Actually, I think there is a more syntactic problem: ocaml uses > special 'kinds' of bindings, for some reason that escapes me: > > type X = .. > class X = .. > exception .. > let X = .. > let rec X = > module X = > > which permit recursion with an 'and' option. Unfortunately, > this syntax does not permit these kinds of bindings to be > mutually recursive (quite aside from the semantic issues). Not aside from, but due to semantic issues. > I find this syntax strange, I would have expected > > let X = > > be enough for all kinds of bindings, determined by the > kind of the right hand side. I understand: you start everything by let and then distinguish the construction you are using by some keyword to determine the kind of the right hand side. It would ressemble something like: let x = type .. let c = class .. let E = exception .. let M = module .. let _ = .. (for expression only) I think the regular syntax of Caml is simpler and more intuitive. Apart from syntax, once more it is a semantic problem: modules are not values, values are not types, exception are not classes, classes are not functors. We prefer to have a direct reflection of these semantics distinctions in the syntax: we hope it may induce a clear distinction in the programmer's ideas. > The distinction between sequential and recursive bindings for > functions seems anomolous [let .. in can be used for that]. It is not anomalous [let .. in cannot be used for that]. This is due to the static binding discipline of Caml. Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Rebinding exception declarations 1999-10-15 7:12 ` Pierre Weis @ 1999-10-17 11:15 ` skaller 0 siblings, 0 replies; 5+ messages in thread From: skaller @ 1999-10-17 11:15 UTC (permalink / raw) To: Pierre Weis; +Cc: caml-list Pierre Weis wrote: > > Actually, I think there is a more syntactic problem: ocaml uses > > special 'kinds' of bindings, for some reason that escapes me: > > > > type X = .. > > class X = .. > > exception .. > > let X = .. > > let rec X = > > module X = > > > > which permit recursion with an 'and' option. Unfortunately, > > this syntax does not permit these kinds of bindings to be > > mutually recursive (quite aside from the semantic issues). > > Not aside from, but due to semantic issues. > > > I find this syntax strange, I would have expected > > > > let X = > > > > be enough for all kinds of bindings, determined by the > > kind of the right hand side. > > I understand: you start everything by let and then distinguish the > construction you are using by some keyword to determine the kind of > the right hand side. It would ressemble something like: > > let x = type .. > let c = class .. > let E = exception .. > let M = module .. > let _ = .. (for expression only) > > I think the regular syntax of Caml is simpler and more intuitive. But if that is the only argument, then your previous claim: > Not aside from, but due to semantic issues. is not quite correct. > Apart from syntax, once more it is a semantic problem: modules are not > values, values are not types, exception are not classes, classes are > not functors. We prefer to have a direct reflection of these semantics > distinctions in the syntax: we hope it may induce a clear distinction > in the programmer's ideas. I accept the intuition, but this leaves the problem that recursions between say, a class and an algebraic type, cannot be expressed directly using the 'and' option. Had the syntax been: let class X = .. and class Y = we could have added and type algebraic = .. There are cases where this can be proved to work. For example, by first abstracting the algebraic types out of the classes (making them type parameters), then declaring the algbraic types, and then instantiating the classes with the appropriate types. I'm not certain, but it seems this is general, so that mixing class and algebraic types recursively should be OK .. if only there were a syntax for it. -- John Skaller, mailto:skaller@maxtal.com.au 1/10 Toxteth Rd Glebe NSW 2037 Australia homepage: http://www.maxtal.com.au/~skaller downloads: http://www.triode.net.au/~skaller ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Rebinding exception declarations 1999-10-14 22:52 ` skaller 1999-10-15 7:12 ` Pierre Weis @ 1999-10-17 14:22 ` Xavier Leroy 1 sibling, 0 replies; 5+ messages in thread From: Xavier Leroy @ 1999-10-17 14:22 UTC (permalink / raw) To: skaller, Manuel Fahndrich; +Cc: 'caml-list@inria.fr' > Actually, I think there is a more syntactic problem: ocaml uses > special 'kinds' of bindings, for some reason that escapes me: > > type X = .. > class X = .. > exception .. > let X = .. > let rec X = > module X = The reason is easy: the syntax and the meaning of the right-hand side depends on the 'kind' of the thing being bound. E.g. "t * t" in the right-hand side can be a product type (for a type t = declaration) or a squaring operation (for a let x = declaration). Even human readers need the initial keyword to know how to make sense of the definition, I guess. > which permit recursion with an 'and' option. Unfortunately, > this syntax does not permit these kinds of bindings to be > mutually recursive (quite aside from the semantic issues). The problem is exactly "semantic issues". We know how to type-check and compile mutually-recursive value definitions, and also mutually-recursive type definitions. Mutual recursion between module definitions, for instance, is a research problem that is still mostly open. Mutual recursion between, say, a module and a class seems at least as problematic. Coming back to Manuel Fähndrich original point on rebinding of exceptions: this looks like a natural thing to have. We can rebind datatype constructors already, so why not exceptions. I'll see what we can do about it. - Xavier Leroy ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1999-10-18 14:16 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1999-10-13 16:59 Rebinding exception declarations Manuel Fahndrich 1999-10-14 22:52 ` skaller 1999-10-15 7:12 ` Pierre Weis 1999-10-17 11:15 ` skaller 1999-10-17 14:22 ` Xavier Leroy
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox