Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: oleg@pobox.com
To: jtbryant@valdosta.edu, Andrej.Bauer@fmf.uni-lj.si
Cc: caml-list@inria.fr
Subject: Re: Type issue
Date: Fri, 23 Nov 2007 21:47:59 -0800 (PST)	[thread overview]
Message-ID: <20071124054759.A0FF4A9AD@Adric.metnet.fnmoc.navy.mil> (raw)


As Alain Frisch mentioned, with polymorphic recursion, inference is in
general impossible. Luckily, polymorphic recursion can be integrated
into a HM system if we require a type annotation on polymorphically
recursive functions. The annotation can come in various forms: for
example, if we use recursive modules, the annotation is given in the
signature. It seems using first-class polymorphism of OCaml records
might be a bit simpler:

type 'a t = Cond of bool t * 'a t * 'a t | Value of 'a;;
  type 'a t = Cond of bool t * 'a t * 'a t | Value of 'a

type ft = {ft : 'a . 'a t -> 'a};;
  type ft = { ft : 'a. 'a t -> 'a; }

let f = 
  let rec f' = {ft = function 
    | Cond (c,t,e) -> if f'.ft c then f'.ft t else f'.ft e
    | Value x -> x}
  in f'.ft;;

 val f : 'a t -> 'a = <fun>

f (Cond ((Value true),(Value 1),(Value 2)));;
- : int = 1

One should think of 'ft' as marking the places where the big-lambda is
introduced and eliminated.  Luckily, the extended value restriction
(or should I say, restricted value restriction) helps us avoid
eta-expansion in the definition of f.


             reply	other threads:[~2007-11-24  5:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-24  5:47 oleg [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-11-23  4:01 Jonathan T Bryant

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=20071124054759.A0FF4A9AD@Adric.metnet.fnmoc.navy.mil \
    --to=oleg@pobox.com \
    --cc=Andrej.Bauer@fmf.uni-lj.si \
    --cc=caml-list@inria.fr \
    --cc=jtbryant@valdosta.edu \
    /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