caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* type generalization of recursive calls
@ 2010-02-17 16:34 Stéphane Gimenez
  2010-02-17 19:41 ` [Caml-list] " Boris Yakobowski
  2010-02-18 14:24 ` Stéphane Gimenez
  0 siblings, 2 replies; 5+ messages in thread
From: Stéphane Gimenez @ 2010-02-17 16:34 UTC (permalink / raw)
  To: The Caml Mailing List

Hi,

I just realized that ocaml generalizes the type of a recursively
defined function *only* for calls which are outside it's own
definition. Recursive calls cannot use a generalized type.

In fact, I'm tring to work with such a data type:

type 'a t =
  | E
  | D of 'a t * 'a t
  | O of 'a
  | I of 'a t t

And, I'm forced to use some dark magic to define simple operations on
it:

let rec map (f : 'a -> 'b) : 'a t -> 'b t =
  begin function
  | E -> E
  | D (t1, t2) -> D (map f t1, map f t2)
  | O a -> O (f a)
  | I tt ->
      I ((Obj.magic map : ('a t -> 'b t) -> 'a t t -> 'b t t) (map f) tt)
  end

Questions:
  - Is it theoreticaly safe to generalize recursive calls ?
  - Is there a syntactical trick to use generalized recursive calls ?
  - Could such a generalization be added to the type checker ?
      - Performance issues ?
      - More obfusctated type checking errors ?

In a related disscution I found, one asked about generalization
between mutualy recursive definitions (same problem). No answers, but
maybe I just lack pointers.

Cheers,
Stéphane


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

end of thread, other threads:[~2010-02-18 14:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-17 16:34 type generalization of recursive calls Stéphane Gimenez
2010-02-17 19:41 ` [Caml-list] " Boris Yakobowski
2010-02-17 20:25   ` Dario Teixeira
2010-02-17 20:33     ` Boris Yakobowski
2010-02-18 14:24 ` Stéphane Gimenez

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