Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: David Brown <caml@davidb.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Insufficient polymorphism in local let.
Date: Fri, 23 Mar 2012 06:12:10 +0100	[thread overview]
Message-ID: <CAPFanBEdWdqAcQNqSSCRkLZ_LqsMK44L1QN_Uo3Va7HaoLfnYA@mail.gmail.com> (raw)
In-Reply-To: <20120323045817.GA26450@davidb.org>

This is a consequence of value restriction, with a direct workaround.
See the FAQ:

  "A function obtained through partial application is not polymorphic enough"
  http://caml.inria.fr/resources/doc/faq/core.en.html#eta-expansion

  let get1 a b =
    let must x = lmust "get2" x in
    ....

On Fri, Mar 23, 2012 at 5:58 AM, David Brown <caml@davidb.org> wrote:
> I'm trying to figure out how to get 'lmust' in 'get2' in the code
> below to work.  It seems that it's type is being inferred as
>
>  string -> string option -> string
>
> instead of
>
>  string -> 'a option -> 'a
>
> The 'must' definition keeps it's polymorphism, as seen in 'get1'.  Is
> there some way I can annotate the definition of 'lmust' so that it
> will work?  Lifting 'lmust' out of 'get2' doesn't seem to help.
>
> Thanks,
> David
>
> let must section name = function
>  | Some o -> o
>  | None ->     Printf.eprintf "Expecting %s in %s\n%!" name section;
>    exit 1
>
> type foo = { a: string; b: int }
>
> let get1 a b =
>  { a = must "get1" "a" a;
>    b = must "get1" "b" b }
>
> let get2 a b =
>  (* This isn't polymorphic enough. *)
>  let lmust = must "get2" in
>  { a = lmust "a" a;
>    b = lmust "b" b }
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


      reply	other threads:[~2012-03-23  5:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-23  4:58 David Brown
2012-03-23  5:12 ` Gabriel Scherer [this message]

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=CAPFanBEdWdqAcQNqSSCRkLZ_LqsMK44L1QN_Uo3Va7HaoLfnYA@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=caml@davidb.org \
    /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