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: Zheng Li <li@p...>
Subject: Re: Smells like duck-typing

Hi,

I would vote for the object solution. However, both record and object have
their own pros and cons. The actual solution should depends on your requirement
and taste. Just for an example, the following data structure is a possibility:

# type +'a t = {title:string; intro:string; extra:'a} constraint 'a = < .. >;;
# let fresh (title,intro,(body:string)) = 
  {title=title; intro=intro; extra=object method body=body end};;
# let blurb ((id:int),title,intro) =
  {title=title; intro=intro; extra=object method id=id end};;
# let print_metadata s = Printf.printf "%d: %s\n" s.extra#id s.title;;
val print_metadata : < id : int; .. > t -> unit = <fun>

Dario Teixeira <darioteixeira@yahoo.com> writes:
> I have been trying to reach a sane modelling in OCaml for a "story"
> data structure in a CMS.  The problem is that I find myself needing
> a degree of expressiveness that I can't find in the language!  I do
> have a working, tentative solution, but it has a few ugly aspects
> that I would very much like to improve.  Details follow.  (Sorry
> for the long post; at least I hope it's not too dense and hard to
> follow).

-- 
Zheng Li
http://www.pps.jussieu.fr/~li