Version française
Home     About     Download     Resources     Contact us    
Browse thread
Smells like duck-typing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Hurt <bhurt@j...>
Subject: Re: [Caml-list] Smells like duck-typing
Dario Teixeira wrote:

>Hi,
>
>(This is a collective reply to all the issues that were raised by my
>previous message; sorry if I don't answer each message individually).
>
>I made the early "reverse inheritance" suggestion somewhat facetiously,
>but judging from the replies, there was a certain amount of confusion
>about what I meant.
>
>I'll try to describe what I have in mind.  I'll do it by modelling
>the problem in an imaginary OCaml-derived language that features
>"reverse inheritance".  Please read on:
>
>
>The "story" class is one that is fully defined.  Think of it as a raw
>block of marble from which the non-important pieces can be carved out.
>To avoid confusion, let's call a class of this kind a "marble-class":
>
>marble-class story (id, title, intro, body) =
>object
>	method id: int = id
>	method title: string = title
>	method intro: string = intro
>	method body: string = body
>end
>
>Now, a "full_story" is one that is also fully defined.  Taking as starting
>point the "story" block-class previously defined, you don't need to carve
>out anything to obtain a full_story:
>
>marble-class full_story (id, title, intro, body) =
>object
>	carves story (id, title, intro, body)
>end
>
>
>However, a "blurb_story" does introduce changes: it can be formed by
>taking the original story as a starting point, and removing the "body"
>chunk of marble.  Note that I am using some new keywords: carves, removes,
>and CARVED:
>
>marble-class blurb_story (id, title, intro) =
>object
>	carves story (id, title, intro, CARVED)
>	removes method body
>end
>
>
>Similarly, a "fresh_story" is a story without the "id" field:
>
>marble-class fresh_story (title, intro, body)
>object
>	carves story (CARVED, title, intro, body)
>	removes method id
>end
>
>  
>

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?

Brian