Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: caml-list@inria.fr (OCAML)
Subject: question on recursive types
Date: Sun, 21 Mar 1999 20:47:55 +0100 (MET)	[thread overview]
Message-ID: <199903211947.UAA20606@miss.wu-wien.ac.at> (raw)

Hello,

I am trying to find a useful approach for sending streams of messages
to objects and have come across the following problem (code example):

  class transformer = object (self)
    method apply_strm s =
      try while true do (Stream.next s) self s done with Stream.Failure -> ()
  end

Method "apply_strm" gets a stream of functions which take as additional
parameters the "self"-object and the rest of the stream.

These functions are called and they again invoke some method in the
"self"-object with the rest of the stream as final parameter (not shown in
example - unnecessary for demonstrating problem).

This approach would allow very flexible interpretation/execution of
message streams as (e.g.) they might be generated by parsers.

Unfortunately, this results in a recursive type, because the elements of
the stream are functions that have to accept the same type of streams
as parameter. I have already tried to explicitely specify the type of
the stream, but it seems impossible to get rid of the error:

  File "bla.ml", line 3, characters 43-44:
  This expression has type
    (< apply_strm : 'a -> 'b; .. > -> 'c -> 'd) Stream.t as 'a
  but is here used with type 'c

How can I (if possible at all) tell the compiler that 'c and 'a are
actually the same type? It doesn't work to use "as" for binding the type
of the stream to an identifier and use this one in place of 'c. E.g.:

  class transformer = object (self : 'self)
    method apply_strm (s: (('self -> 'a -> unit) Stream.t as 'a)) =
      try while true do (Stream.next s) self s done with Stream.Failure -> ()
  end

The problem can be shown with a shorter, different and now probably not
very useful expression:

  let f (h::t) = h t;;

Best regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl




             reply	other threads:[~1999-03-22  7:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-21 19:47 Markus Mottl [this message]
1999-03-22 12:53 ` Jerome Vouillon

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=199903211947.UAA20606@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=caml-list@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