caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jeremy Yallop <jeremy.yallop@ed.ac.uk>
To: Jake Donham <jake@donham.org>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] surprising type error with labels
Date: Thu, 19 Jun 2008 22:58:59 +0100	[thread overview]
Message-ID: <485AD6A3.7060606@ed.ac.uk> (raw)
In-Reply-To: <c7e4e9f0806191438j9f7a742x6989fc2d7b192a0f@mail.gmail.com>

Jake Donham wrote:
> Why does
> 
>  ListLabels.find (fun _ -> true) [];;
> 
> produce
> 
>  Characters 16-31:
>    ListLabels.find (fun _ -> true) [];;
>                    ^^^^^^^^^^^^^^^
>  This expression should not be a function, the expected type is
>  ('a -> 'b) list
> 
> I thought the rule was that "if an application is total, labels may be
> omitted." (4.1 in the manual). (I was trying to do module List =
> ListLabels at the top of a file.) Thanks,

Applications of functions whose return types are type variables are 
never considered total, since it's possible to pass extra arguments if 
the type variable is instantiated to a function type.  For example, 
ListLabels.find has type

    f:('a -> bool) -> 'a list -> 'a

If the type variable is instantiated to `bool -> bool', say, then you 
can pass more than two arguments:

    ListLabels.find ~f:(fun f -> f false) [not] false

You can use the function without labels if you fix its return type:

    (ListLabels.find :  f:_ -> _ -> int) (fun _ -> true) []

Jeremy.


  reply	other threads:[~2008-06-19 21:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-19 21:38 Jake Donham
2008-06-19 21:58 ` Jeremy Yallop [this message]
2008-06-20 12:53   ` [Caml-list] " Mark Shinwell
2008-06-20 13:39     ` Jeremy Yallop

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=485AD6A3.7060606@ed.ac.uk \
    --to=jeremy.yallop@ed.ac.uk \
    --cc=caml-list@inria.fr \
    --cc=jake@donham.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;
as well as URLs for NNTP newsgroup(s).