Developing Applications with Objective CAML
started 7/13/2002; 3:34:46 AM - last post 7/31/2002; 2:49:34 PM
|
|
jon fernquest - Developing Applications with Objective CAML
7/13/2002; 3:34:46 AM (reads: 1960, responses: 7)
|
|
Developing Applications with Objective CAML |
On the mixed use of the object-oriented and functional programming
paradigms in OCAML:
Many problems necessitate recursive data types and operations which
manipulate values of these types. It often happens that the problem
evolves, sometimes in the course of implementation, sometimes during
maintenance, requiring an extension of the types and operations. Neither
of these two models permits extension in both ways. In the functional/modular
model, types are not extensible, but one can create new functions (operations)
on the types. In the object model, one can extend the objects, but not the
methods (by creating a new subclass on an abstract class which
implements its methods.) In this respect, the two models are duals.
The advantage of uniting these two models in the same language is to
be able to choose the most appropriate model for the resolution of the
problem in question and to mix them in order to overcome the limitations of each model.
"Comparison of the Models of Organisation" (Chapter 16)
briefly discusses mixing the two paradigms.
In the
example
given, the conclusion is that,
"the extension of data and methods is easier in the object model when it is combined with the functional model."
To what extent is the approach taken here applicable to functional .NET languages?
You can download the book in a variety of formats.
Posted to object-functional by jon fernquest on 7/13/02; 7:48:13 AM
|
|
|
|
Daniel Bonniot - Re: Developing Applications with Objective CAML
7/30/2002; 5:17:10 AM (reads: 1214, responses: 3)
|
|
It is a first step to have both extensible data (objects) and extensible operations (functions on datatypes) in the same language. However, in OCaml they are just two unrelated concepts, which means a bigger, less orthogonal language. And above all, you are still forced to chose, for each data structure, to go the functional or the object-oriented way. What if you need both kinds of extensions? What if you don't know in advance which one will be needed?
Multi-methods allow to have this "extensibility in both directions" inside a single concept. There is a page on the Nice Wiki that discusses this issue.
|
|
Ehud Lamm - Re: Developing Applications with Objective CAML
7/30/2002; 5:26:03 AM (reads: 1288, responses: 2)
|
|
I renew my request for a pointer to a good discussion on the differences between algebraic datatypes and inheritance (though section 1.1 of the icfp01 paper gives a nice explanation).
|
|
Ehud Lamm - Re: Developing Applications with Objective CAML
7/30/2002; 5:30:44 AM (reads: 1210, responses: 2)
|
|
Inehritance allows you to extend operations, while reusing the implementation of the parent (which may be designed from the start to give a partial implementation, if this is what you want).
Obviously, this creates strong coupling which may become problematic over time.
|
|
Daniel Bonniot - Re: Developing Applications with Objective CAML
7/30/2002; 5:42:08 AM (reads: 1332, responses: 1)
|
|
I'm not sure what you would like. Is the wiki page linked above partly answering the question?
It depends what you mean by inheritance. In that page, which is speaking about languages with multi-method, inheritance is both the addition of fields in a data-structure and the capacity to be matched by operations on the super-class. The claim is that algebraic datatypes are subsumed by this kind of inheritance, which allows the addition of new cases modularly, in addition to (toplevel) pattern matching.
|
|
Daniel Bonniot - Re: Developing Applications with Objective CAML
7/30/2002; 5:46:44 AM (reads: 1272, responses: 1)
|
|
A problem with the addition of operations by subclassing is in the typing. If you use a class A from an imported module and want to add an operation on it, you can declare a subclass A'. That works fine if you create the instance (with new A') but not it you get an instance of A from the outer world.
|
|
Ehud Lamm - Re: Developing Applications with Objective CAML
7/30/2002; 5:55:21 AM (reads: 1383, responses: 0)
|
|
I am looking for something more introductory. Something I can give my students, that know a bit about inheritance (e.g., learned Java), and read a basic tutorial on Haskell including a few pages about algebraic datatypes.
|
|
Ehud Lamm - Re: Developing Applications with Objective CAML
7/31/2002; 2:49:34 PM (reads: 1299, responses: 0)
|
|
If you use a class A from an imported module and want to add an operation on it, you can declare a subclass A'. That works fine if you create the instance (with new A') but not it you get an instance of A from the outer world.
I am not sure I understand the exact problem you are referring to. Can you give an example?
Perhaps related is the way Ada allows you to pass as a generic parameter a tagged type (that's Ada talk for a type that can be extended via inheritance), which can then be extended by the generic unit. This can be used for mixin inheritance.
|
|
|
|