Browse thread
Smells like duck-typing
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Arnaud Spiwack <aspiwack@l...> |
| Subject: | Re: [Caml-list] Smells like duck-typing |
First, let us emphasize that this goes down to the original "option" thing, but in a more dynamic fashion. It is very possible to wrap it back with phantom types, which would probably be a good idea in this case. My taste for this sort of thing is to make all this a finite map of some sort (might be implemented as a list, but the primitive should ensure a form of unicity, therefore an additional layer of abstract datatype). Then you would need a type to query over : "field_field = [ `Title | `Intro | `Body | `Field ]. Implement a function "fetch" that returns you a field_t or raises an exception (you can do similarily a function "mem" etc). Then you can define let title m = let `Title s = fetch `Title m in s;; and give it type [> `Title ] story -> string (to be sure not to raise an exception, modulo right phantom type invariants). That's my own methodology for this sort of types. Arnaud Spiwack Dario Teixeira a écrit : >> I would use something weaker, and I wouldn't use objects >> either. To me, this is essentially a dynamic scenario, >> so the data type should be dynamic. For example: >> >> type field_t = [ >> | `Title of string >> | `Intro of string >> | `Body of string >> | `Field of string * string >> ] >> >> type story_t = field_t list >> >> > > Hi, > > Interesting idea, but how would you access the fields in a convenient > manner? Note that nothing beats record access (say, story.title) or even > object method call (story#title) in convenience and readability. > > (I guess the convenience aspect could be sorted out with a syntax > extension, but then we're moving into far more complex territory > than I hope is necessary...) > > Cheers, > Dario > > > > > ___________________________________________________________ > Want ideas for reducing your carbon footprint? Visit Yahoo! For Good http://uk.promotions.yahoo.com/forgood/environment.html > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >