caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: caml-list@yquem.inria.fr
Subject: divergent type
Date: Wed, 15 Aug 2007 13:02:51 +1000	[thread overview]
Message-ID: <1187146971.6765.22.camel@rosella.wigram> (raw)

Sorry for asking a general typing question not specifically related
to Ocaml .. also, I don't really know how to ask the question properly
(if I did I would know the answer too).

I have a problem in Felix compiler with infinite types. For example
the type of

	fun f(x:int)=>x,f x

is 

	(int * u) as u

which cannot be represented. In Ocaml with -rectypes this is a
legitimate type:

# let rec x = 1,x;;
val x : int * 'a as 'a =
  (1,
   (1,...

which is representable because Ocaml uses boxing (intensional
polymorphism).Smly:

# let rec f x = 1, f x;;
val f : 'a -> (int * 'b as 'b) = <fun>

Felix supports type recursion through pointers, variants also
allow it because they're modelled as pointers (boxed),
and of course functions are boxed (closures).

However some type equations (recursive types) have no
solution at all:

# let rec f x = f (x,x);;    
val f : ('a * 'a as 'a) -> 'b = <fun>

The return type is divergent: Ocaml put 'b here, but
it is a 'hack' the type of the value 'returned' is unrelated to
the type of the value input. Note that this function CAN be modified
to actually return a definite value:

let rec f n x = if x <= 0 then () else f (n-1) (x,x)

is convergent. (It is dependently type-able?)

In any case there seem to be THREE kinds of type:

1. Ordinary types.
2. Finite Recursive types (eg lists)
3. Divergent types

Perhaps someone can throw a bit more light on this?

In Felix I need to detect the difference between an 
incidental recursion (a polymorphic function just happens to call
itself for an unrelated/non-recursive purpose such as mapping
a tuple: such 'recursion' always terminates because the input
term is finite), a representable recursive type (such as a list),
and an infinite expansion. And I note the distinctions are not
representation independent (since Ocaml can handle recursive
products whilst Felix cannot do so without using a pointer).

Help!

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


                 reply	other threads:[~2007-08-15  3:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1187146971.6765.22.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --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).