caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Wohlwend <micha-1@fantasymail.de>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Request for example where type annotation are required
Date: Mon, 19 Sep 2005 22:59:36 +0200	[thread overview]
Message-ID: <200509192259.36586.micha-1@fantasymail.de> (raw)
In-Reply-To: <432F1DC5.2000607@univ-savoie.fr>

On Monday 19 September 2005 22:21, Christophe Raffalli wrote:
> I am looking for small ML examples (using variants, modules, objects,
> etc ...)
> Where one needs to write type information to be able to type-check the
> program with OCaml

As my example, this should be a try of linked objects (like dllist od extlib):

class ['a] node = object(self:'a)
    val mutable nx = nil
    method next = nx
    method set_next n = nx <- n
    method apply f  upto =
        f self; if self <> upto then self#next#apply f upto
end;;

it doesn't work; the problem is the "nil" objects to initalize it, i cannot 
get this right, there are allways typing errors. Can this be defined without 
type-annotations?

ahem, this one works easily :-) 

class ['a] node = object(self:'a)
    val mutable nx =(Obj.magic 0 : 'a) 
    method next = nx
    method set_next n = nx <- n
    method apply (f: 'a->unit)  upto =
        f self; if self <> upto then self#next#apply f upto
    initializer nx <- self
end;;
   
let a = new node;;
-------------------------------------------------------------

 Michael


      reply	other threads:[~2005-09-19 20:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-19 20:21 Christophe Raffalli
2005-09-19 20:59 ` Michael Wohlwend [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200509192259.36586.micha-1@fantasymail.de \
    --to=micha-1@fantasymail.de \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).