caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Christoph Höger" <christoph.hoeger@tu-berlin.de>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] why is this definition less general?
Date: Thu, 27 Aug 2015 11:59:55 +0200	[thread overview]
Message-ID: <55DEDF9B.5020006@tu-berlin.de> (raw)

Dear all,

I found that I can evade the "first occurence unifies" behavior of
recursive polymorphic functions by using explicit polymorphic types:

utop # let rec a_to_opt : 'a . ('a -> 'a option) = fun x -> None and
int_to_opt (i:int) = a_to_opt i and str_to_opt (s:string)= a_to_opt s ;;

val a_to_opt : 'a -> 'a option = <fun>


               val int_to_opt : int -> int option = <fun>


                              val str_to_opt : bytes -> bytes option = <fun>

When I try to annotate the type in the body of a_to_opt, however, I get
a "less general" error:

utop # let rec a_to_opt : 'a . ('a -> 'a option) = fun x -> (None : 'a
option) and int_to_opt (i:int) = a_to_opt i and str_to_opt (s:string)=
a_to_opt s ;;
Error: This definition has type 'a -> 'a option which is less general
than

                          'a0. 'a0 -> 'a0 option

Obviously, 'a is bound by its first occurrence in the type annotation,
here. Can someone explain this behavior?

-- 
Christoph Höger

Technische Universität Berlin
Fakultät IV - Elektrotechnik und Informatik
Übersetzerbau und Programmiersprachen

Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin

Tel.: +49 (30) 314-24890
E-Mail: christoph.hoeger@tu-berlin.de

             reply	other threads:[~2015-08-27  9:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-27  9:59 Christoph Höger [this message]
2015-08-27 10:11 ` Jeremie Dimino

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=55DEDF9B.5020006@tu-berlin.de \
    --to=christoph.hoeger@tu-berlin.de \
    --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;
as well as URLs for NNTP newsgroup(s).