Browse thread
Smells like duck-typing
-
Dario Teixeira
- Arnaud Spiwack
- Daniel_Bünzli
- Chris King
- Zheng Li
- Vincent Aravantinos
- Richard Jones
- Dario Teixeira
- Vincent Aravantinos
[
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: | Dario Teixeira <darioteixeira@y...> |
| Subject: | Re: [Caml-list] Smells like duck-typing |
> So now you've defined full_story, blurb_story, and fresh_story as
> types. Now, I write:
>
> let get_body (story: full_story) = story#get_body;;
> let my_blurb = new blurb_story(id, "A Title", "An Intro");;
> let my_body = get_body my_blurb;;
>
> what happens?
Hi,
Well, that's only a problem if you insist in thinking in terms
of inheritance. Remember that the semantics of marble-carving
are NOT "all that works on full_story should also work on blurb_story",
but the other way around.
Also, imagine you were to add the "get_body" method to the root
"story" class. The type system in Marble-Caml is smart enough
to tell you that since the blurb_story carved out the "body" field,
then it must also carve out methods that use it. Aren't imaginary
languages wonderfull?... :-)
(In addition, note that in any real world situation, it wouldn't
make any sense for the user to want to invoke get_body on a blurb
object -- after all, by definition blurbs have no body).
Cheers,
Dario
___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/