* [Caml-list] What are Classes for in O'Caml? @ 2002-11-08 13:24 Oleg 2002-11-08 13:45 ` Michael Wohlwend 0 siblings, 1 reply; 8+ messages in thread From: Oleg @ 2002-11-08 13:24 UTC (permalink / raw) To: caml-list Hi I noticed many of the discussions on this list are about classes, which probably means that people find classes useful in O'Caml. I'm curious as to what classes are for in O'Caml (in view of the fact that it already has abstract data types) ? Oleg ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] What are Classes for in O'Caml? 2002-11-08 13:24 [Caml-list] What are Classes for in O'Caml? Oleg @ 2002-11-08 13:45 ` Michael Wohlwend 2002-11-08 13:57 ` Luc Maranget ` (3 more replies) 0 siblings, 4 replies; 8+ messages in thread From: Michael Wohlwend @ 2002-11-08 13:45 UTC (permalink / raw) To: caml-list On Freitag, 8. November 2002 14:24, Oleg wrote: > I'm curious as to what classes are for in O'Caml (in view of the fact that > it already has abstract data types) ? I'm wondering about the same question :-) I got to ocaml two weeks ago and the first thing I realized was that due the the functional programming style and the module system the need for oo-programming is much lower than with imperative style languages (at least for me). Has somone found a *best* solution (for his tasks) to combine them (classes und modules) or is it really just a matter of taste? Michael ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] What are Classes for in O'Caml? 2002-11-08 13:45 ` Michael Wohlwend @ 2002-11-08 13:57 ` Luc Maranget 2002-11-09 12:44 ` Didier Remy 2002-11-08 19:50 ` Chris Hecker ` (2 subsequent siblings) 3 siblings, 1 reply; 8+ messages in thread From: Luc Maranget @ 2002-11-08 13:57 UTC (permalink / raw) To: mwohlwend; +Cc: caml-list > > > I'm curious as to what classes are for in O'Caml (in view of the fact that > > it already has abstract data types) ? You'll find some detailled answers to this question in the book ``Developping Applications With Objective Caml'', Part III. The book is available online at <http://caml.inria.fr/oreilly-book/html/index.html> --Luc ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] What are Classes for in O'Caml? 2002-11-08 13:57 ` Luc Maranget @ 2002-11-09 12:44 ` Didier Remy 0 siblings, 0 replies; 8+ messages in thread From: Didier Remy @ 2002-11-09 12:44 UTC (permalink / raw) To: Luc Maranget; +Cc: mwohlwend, caml-list > > I'm curious as to what classes are for in O'Caml (in view of the fact that > > it already has abstract data types) ? > > > You'll find some detailled answers to this question in the book > ``Developping Applications With Objective Caml'', Part III. > > The book is available online at > <http://caml.inria.fr/oreilly-book/html/index.html> You may also find some comparison of both styles in my APPSEM course notes: http://cristal.inria.fr/~remy/cours/appsem/ In particular, in Chapter 5: http://cristal.inria.fr/~remy/cours/appsem/ocaml-mixins.html Didier ---------------- @InCollection{Remy!appsem, author = "Didier R{\'{e}}my", title = "{U}sing, {U}nderstanding, and {U}nraveling the {OC}aml {L}anguage", booktitle = "{A}pplied {S}emantics. Advanced Lectures. LNCS 2395.", publisher = "Springer Verlag", year = "2002", editor = "Gilles Barthe", pages = "413--537", isbn = {3-540-44044-5} } ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] What are Classes for in O'Caml? 2002-11-08 13:45 ` Michael Wohlwend 2002-11-08 13:57 ` Luc Maranget @ 2002-11-08 19:50 ` Chris Hecker 2002-11-08 19:59 ` M E Leypold @ labnet 2002-11-09 2:54 ` brogoff 3 siblings, 0 replies; 8+ messages in thread From: Chris Hecker @ 2002-11-08 19:50 UTC (permalink / raw) To: mwohlwend, caml-list > > I'm curious as to what classes are for in O'Caml (in view of the fact that > > it already has abstract data types) ? Objects and classes versus modules in Objective Caml http://pauillac.inria.fr/~xleroy/talks/icfp99.ps.gz Chris ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] What are Classes for in O'Caml? 2002-11-08 13:45 ` Michael Wohlwend 2002-11-08 13:57 ` Luc Maranget 2002-11-08 19:50 ` Chris Hecker @ 2002-11-08 19:59 ` M E Leypold @ labnet 2002-11-08 20:41 ` Brian Hurt 2002-11-09 2:54 ` brogoff 3 siblings, 1 reply; 8+ messages in thread From: M E Leypold @ labnet @ 2002-11-08 19:59 UTC (permalink / raw) To: mwohlwend; +Cc: caml-list Michael Wohlwend writes: > On Freitag, 8. November 2002 14:24, Oleg wrote: > > I'm curious as to what classes are for in O'Caml (in view of the > > fact that it already has abstract data types) ? > Has somone found a *best* solution (for his tasks) to combine them > (classes und modules) or is it really just a matter of taste? The following is only a suggestion: - Modules are units of compilation, hide away implemantation details and capsule namespaces. In a sense they are 'compile-time constructs'. - ADT's -- just what you should use to represent your data. Always (well: almost) use abstractions, that is, hide representation details and make operations available only by procdures / functions. Strongly related ADTs (i.e. vectors and matrices) which need to know each others representation should go into one module, but not strongly related ADTs into different modules. Note, that ADTs are _values_. - Classes, well, let's talk about objects (in my book classes are only a method to get objects ...): Objects are storage for state. Note: an object might contain state A and later state B. Applying a similar sentence to the type list doesn't make sense: You have either list A (one value) or list B (another value). There is no later time: When the name get's bound, it becomes a symbol for that value until it goes out of scope [*]. Objects make sense, when you want to have operations that do destruktive update (recycle the memory representation of their input to get the output). And this is useful to encapsule program external state (Printer, Filesystem, ...), where the old state is also lost after an operation [**]. Hope that makes sense to anyone. Regards -- Markus [*] I know, ML has imperative features. I'm talking about funktional programming here (pushing around _values_, not: "updating variables" or "updating memory locations"). Object orientation (in a sense) is really an imperative programming style :-). [**] Mercury has a special 'unique' spezifier for this kind of values, which pass into an operation and might not be referred to afterwards. This way Mercury deals with state changes in the outside world (I/O) in a purely functional way. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] What are Classes for in O'Caml? 2002-11-08 19:59 ` M E Leypold @ labnet @ 2002-11-08 20:41 ` Brian Hurt 0 siblings, 0 replies; 8+ messages in thread From: Brian Hurt @ 2002-11-08 20:41 UTC (permalink / raw) To: M E Leypold @ labnet; +Cc: mwohlwend, caml-list I'm still a newbie at Ocaml- but here's my $0.02: OO programming has a classic analysis technique- 'is a' relationships vr.s 'has a' relationships. If a relationship is an 'is a' relationship, you use object inheritance, if it's a 'has a' relationship, you use a member variable. Caml's ADT concept adds a third case- the 'of' case. Think about it- what does 'a list mean as a type? It means it's a list *of* objects of type a. Java doesn't have a natural way to express the 'of' relationship between two types. So you end up with collections only handling Objects (abusing the has-a relationship), and lots of unnecessary typecasting (subverting the type system, and causing run time errors and hard to find bugs). C++ introduced Templates to express the 'of' relationship, but (IMHO) did it nearly perfectly bad. I can't think of many ways to make C++ templates worse. Just like you can (and many people do) confuse is-a and has-a relationships, and make it (more or less) work. Likewise, you can swap either of them in for of relationships and make it (more or less) work. But there's a difference between 'workable (more or less)' and 'correct'. I like languages where I can express what I mean, and use the right language construct for the right relationship. I'm probably not giving ADTs the credit here they really deserve. But that's how I've been thinking of them. Brian On Fri, 8 Nov 2002, M E Leypold @ labnet wrote: > > > Michael Wohlwend writes: > > On Freitag, 8. November 2002 14:24, Oleg wrote: > > > > I'm curious as to what classes are for in O'Caml (in view of the > > > fact that it already has abstract data types) ? > > > Has somone found a *best* solution (for his tasks) to combine them > > (classes und modules) or is it really just a matter of taste? > > > The following is only a suggestion: > > - Modules are units of compilation, hide away implemantation details > and capsule namespaces. In a sense they are 'compile-time > constructs'. > > - ADT's -- just what you should use to represent your data. Always > (well: almost) use abstractions, that is, hide representation > details and make operations available only by procdures / > functions. Strongly related ADTs (i.e. vectors and matrices) which > need to know each others representation should go into one module, > but not strongly related ADTs into different modules. Note, that > ADTs are _values_. > > - Classes, well, let's talk about objects (in my book classes are > only a method to get objects ...): Objects are storage for state. > Note: an object might contain state A and later state B. Applying > a similar sentence to the type list doesn't make sense: You have > either list A (one value) or list B (another value). There is no > later time: When the name get's bound, it becomes a symbol for > that value until it goes out of scope [*]. > > Objects make sense, when you want to have operations that do > destruktive update (recycle the memory representation of their > input to get the output). And this is useful to encapsule program > external state (Printer, Filesystem, ...), where the old state is > also lost after an operation [**]. > > Hope that makes sense to anyone. > > Regards -- Markus > > > > [*] I know, ML has imperative features. I'm talking about funktional > programming here (pushing around _values_, not: "updating variables" > or "updating memory locations"). Object orientation (in a sense) is > really an imperative programming style :-). > > [**] Mercury has a special 'unique' spezifier for this kind of values, > which pass into an operation and might not be referred to > afterwards. This way Mercury deals with state changes in the outside > world (I/O) in a purely functional way. > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] What are Classes for in O'Caml? 2002-11-08 13:45 ` Michael Wohlwend ` (2 preceding siblings ...) 2002-11-08 19:59 ` M E Leypold @ labnet @ 2002-11-09 2:54 ` brogoff 3 siblings, 0 replies; 8+ messages in thread From: brogoff @ 2002-11-09 2:54 UTC (permalink / raw) To: caml-list On Fri, 8 Nov 2002, Michael Wohlwend wrote: > I got to ocaml two weeks ago and the first thing I realized was that due the > the functional programming style and the module system the need for > oo-programming is much lower than with imperative style languages (at least > for me). I tend to use the class system to ameliorate the annoying limitations of OCaml records. You know, no overloaded field labels, functions can't be polymorphic over a set of labels, that kind of thing. I'd be thrilled if I could have all of this stuff in a record system and get pattern matching back. > Has somone found a *best* solution (for his tasks) to combine them (classes > und modules) or is it really just a matter of taste? In addition to the O'Reilly book and Xavier's talk slides, take a gander at Didier Remy's APPSEM notes, where he discusses this issue in detail, and provides pointers to a symbolic algebra program which uses modules and classes together. -- Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2002-11-09 10:47 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-11-08 13:24 [Caml-list] What are Classes for in O'Caml? Oleg 2002-11-08 13:45 ` Michael Wohlwend 2002-11-08 13:57 ` Luc Maranget 2002-11-09 12:44 ` Didier Remy 2002-11-08 19:50 ` Chris Hecker 2002-11-08 19:59 ` M E Leypold @ labnet 2002-11-08 20:41 ` Brian Hurt 2002-11-09 2:54 ` brogoff
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox