caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* recursive types
@ 2008-03-24  3:16 Jacques Le Normand
  2008-03-24  9:02 ` Remi Vanicat
  0 siblings, 1 reply; 16+ messages in thread
From: Jacques Le Normand @ 2008-03-24  3:16 UTC (permalink / raw)
  To: caml-list caml-list

[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

hello again list
is it possible to have mutually recursive classes and types? I'm trying to
implement the zipper, and this is what I came up with:

class type node_wrapper =
object
  method identify : string
  method get_child_location : location
end

class virtual nodeable =
object(self)
  method virtual to_node_wrapper : node_wrapper
end

type path = (nodeable list * location * nodeable list) option
and location = Loc of nodeable * path


which, of course, doesn't type check


a simpler test case would be

class a =
  val b : c
end

type c = a

thanks for all the help so far!
--Jacques

[-- Attachment #2: Type: text/html, Size: 723 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread
* recursive types
@ 2004-12-13  9:44 nakata keiko
  0 siblings, 0 replies; 16+ messages in thread
From: nakata keiko @ 2004-12-13  9:44 UTC (permalink / raw)
  To: caml-list; +Cc: keiko

Can I have recursive types going through both of "normal" types and
class types?

I would like to define something like

type exp = [`Num of obj |`Neg of obj] 
and class type obj = 
  object 
    method eql : exp ->  bool
  end

Thanks,
Keiko 


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: type recursifs et abreviations cyclique and Co
@ 1997-11-25  4:40 Jason Hickey
  1997-11-25 10:09 ` recursive types Xavier Leroy
  0 siblings, 1 reply; 16+ messages in thread
From: Jason Hickey @ 1997-11-25  4:40 UTC (permalink / raw)
  To: caml-list
  Cc: crary, hayden, Olivier Montanuy, Emmanuel Engel, Jerome Vouillon,
	Francisco Valverde

Although my French is not what I would like, I gather that the feature
of general recursive types in OCaml has been drawn back because it is
prone to error.  For instance, the type I originally proposed

    type x = x option

is not allowed because types of that form are prone to error.  The
solution would be to apply an explicit boxing:

    type x = X of x option.

I would like to make an argument against this policy.

1.  The interpretation of the general recursive type has a
    well-defined type theoretic meaning.  For instance, the type

        type x = x option

    is isomorphic to the natural numbers.  The _type_theory_ does not
    justify removing it from the language.  Why not issue a warning rather
    than forbidding the construction?  For instance, the following code is
    not forbidden:

        let flag = (match List.length [] with 0 -> true)

    even though constructions of this form are "prone to error,"
    and generate warning messages.

2.  The policy imposes a needless efficiency penalty on type
    abstraction.  For instance, suppose we have an abstract type

        type 'a t

    then we can't form the recursive type

        type x = x t

    without a boxing.  Although the type

        type x = X of x t

    is equivalent, it requires threading a lot of superfluous X's through
    the code, and ocaml will insert an extraneous boxing for each
    occurrence of an item of type x in t.  Consider an unlabeled
    abstract binary tree:

        type 'a t = ('a option) * ('a option)    (* abstract *)
        ...
        type node = X of node t

    Every node is boxed, with a space penalty that is
    linear in the number of nodes.

3.  If the type system can be bypassed with an extraneous boxing,

        type x = x t   ----->   type x = X of x t

    then what is the point?

4.  (Joke) All significant programs are "prone to error."  Perhaps the
    OCaml compiler should forbid them all!

    I use this construction extensively in Nuprl (theorem proving)
    and Ensemble (communications) applications; do I really need
    to change my code?

Jason






^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2008-03-24  9:02 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20050506044107.1698.70519.Mailman@yquem.inria.fr>
2005-11-15 22:44 ` Recursive types Swaroop Sridhar
2005-11-15 23:40   ` [Caml-list] " Jacques Garrigue
2005-11-16  2:20     ` Keiko Nakata
2005-11-16  6:47       ` Alain Frisch
2005-11-16  7:40         ` Keiko Nakata
2005-11-16  8:55           ` Jacques Garrigue
2005-11-17  1:45             ` Keiko Nakata
2005-11-16  3:28     ` Swaroop Sridhar
2005-11-16  8:38       ` Jacques Garrigue
2005-11-16 23:00         ` Swaroop Sridhar
2005-11-16 23:56           ` Swaroop Sridhar
2008-03-24  3:16 recursive types Jacques Le Normand
2008-03-24  9:02 ` Remi Vanicat
  -- strict thread matches above, loose matches on Subject: below --
2004-12-13  9:44 nakata keiko
1997-11-25  4:40 type recursifs et abreviations cyclique and Co Jason Hickey
1997-11-25 10:09 ` recursive types Xavier Leroy
1997-11-25 15:43   ` Jason Hickey

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).