Newsgroups: comp.lang.ml, comp.lang.functional
Followup-To: comp.lang.ml
From: Xavier.Le...@see.my.sig.for.address (Xavier Leroy)
Date: 1999/07/12
Subject: Re: Objective CAML syntax
Wow, that's a lot of questions. Let me try to answer them constructively > - Why self is not a keyword of the language ? (like this in C++) I remember discussing this with the designers of the object part of OCaml, Jérôme Vouillon and Didier Rémy. The arguments in favor of not having "self" as a keywords were 1- this makes one fewer reserved identifier, 2- you can call the self argument "self" or "this" depending on whether you come from a Smalltalk or C++/Java background, and 3- the ability to rename the self argument like you'd rename the parameter of a function comes in handy for giving a reduction semantics to the language. > - Why virtual methods are always abstract ? (in C++, you can define the I detect a possible keyword confusion here. Methods in OCaml are > implementation of an abstract method, who can be called by the subclass) always "virtual" in the C++ sense: they can always be overriden in subclasses and are always subject to dynamic dispatch and are always subject to dynamic dispatch at method invocation time. The "virtual" keyword in OCaml denotes what is called "pure virtual" methods in C++ or "abstract" methods in Java: the method is just declared but no implementation of the method is provided, leaving the actual implementation to the subclasses. The following chart should clear potential misunderstandings: C++ Java OCaml non-virtual methods static methods functions > - Why can't we define a parametrized method ? (i know that O'Lab try I don't understand the question. Methods can take (value) parameters: > this issue, but what is the reason ?) method f x y = x + y In addition, classes can also be parameterized by initialization > - What is the need of "functionnal object" and is strane notation {< ... In OCaml, data structures come in two flavors: immutable and mutable. > >} ? Immutable structures correspond to a so-called "functional" programming style where you rebuild data structures as needed. Mutable structures correspond to an "imperative" programming style where data structures are modified in place. The "functional" style has definite advantages in terms of software reliability, ease of formal specification, and ability to share sub-structures safely. It is true that most OO languages make object fields mutable by To the best of my knowledge, no mainstream OO language supports > - What is the need of binary method concept ? It's a standard programming trick in class-based OO languages. In those languages, you attach operations to objects. If your operation naturally operates on two or more objects (e.g. equality), you must attach the operation to one of the objects and pass the others as parameters to the method. If you look at the Java API, for instance, you'll see plenty of binary methods, e.g. "equals" in java.lang.Object. Binary methods raise many hairy typing problems, requiring either > - What is the need of functor concept for modules ? Functors are modules parameterized by modules. They allow you to have a module A that you can connect both to a module B and another module B' (implementing differently the same interface) in the same program. One common use of functors is as a mass parameterization mechanism. Another common use of functors is to represent parameterized abstract For more examples of functors, see Robert Harper's course notes on SML, > - Parameters place after de class name are for the constructor; Good question. In OCaml 2.00 and up, the class language lets you > but how can we define multiple constructors ? express this as partial application of classes. Assume for instance that you're defining a class of hash tables parameterized by the initial size of the table: class hashtable size = To provide a "constructor" with a default size of 10, you'd just do: class hashtable_with_default_size = hashtable 10 Then, in your program, new hashtable_with_default_size gives you a hashtable of size 10, and new hashtable 123 gives you one with size 123. While it may look like both hash tables > And, in general, CAML has a simple and easy reading syntax. Why Objective Not everyone will agree with you here. For instance, there seems to > CAML, for the object extension, has a complicated one ? be a popular conception these days that any syntax that is not based on braces suck, period. To me, the object part of OCaml has a richer and more complex syntax Anoter reason is that the core OCaml language is at least 15 years Hope this answers your (numerous) questions. - Xavier Leroy You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||