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: William D. Neumann <wneumann@c...>
Subject: Re: [Caml-list] Smells like duck-typing
On Thu, 18 Oct 2007 12:43:10 -0400, Brian Hurt wrote

> 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?

One would assume the same thing that happens if you were to do:

class full_story = object inherit blurb_story val body method body = body 
end;;
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;;

That is an error indicating that my_body has type < id : int; title : 
string; summary : string > but is used with type < get_body : string ..>, < 
id : int; title : string; summary : string > has no method get_body.

No?

--

William D. Neumann