caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ignore in postfix position
@ 2018-01-09 11:49 Gerd Stolpmann
  2018-02-07 11:09 ` Josh Berdine
  0 siblings, 1 reply; 2+ messages in thread
From: Gerd Stolpmann @ 2018-01-09 11:49 UTC (permalink / raw)
  To: caml-list


[-- Attachment #1.1: Type: text/plain, Size: 971 bytes --]

Hi list,

the "ignore" function behaves specially when applied to a partial function:

# ignore (fun _ -> ());;
Warning 5: this function application is partial,
maybe some arguments are missing.

This very useful warning is not emitted, however, when I switch to a
slight variation, like:

# (fun _ -> ()) |> ignore

I like this post-fix syntax more than the original because "ignore"
isn't then as distracting, but it's a pity that the warning can no
longer be generated. I am wondering whether this behavior is deeply
anchored in the inference engine or whether this is improvable.

Gerd

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] ignore in postfix position
  2018-01-09 11:49 [Caml-list] ignore in postfix position Gerd Stolpmann
@ 2018-02-07 11:09 ` Josh Berdine
  0 siblings, 0 replies; 2+ messages in thread
From: Josh Berdine @ 2018-02-07 11:09 UTC (permalink / raw)
  To: caml-list

Hi Gerd,

> On Jan 9, 2018, at 11:49 AM, Gerd Stolpmann <info@gerd-stolpmann.de> wrote:
> 
> the "ignore" function behaves specially when applied to a partial function:
> 
> # ignore (fun _ -> ());;
> Warning 5: this function application is partial,
> maybe some arguments are missing.
> 
> This very useful warning is not emitted, however, when I switch to a
> slight variation, like:
> 
> # (fun _ -> ()) |> ignore
> 
> I like this post-fix syntax more than the original because "ignore"
> isn't then as distracting, but it's a pity that the warning can no
> longer be generated. I am wondering whether this behavior is deeply
> anchored in the inference engine or whether this is improvable.

I don't know if treating reverse application similarly to the current treatment of application would be difficult, but as an alternative I tend to put a type ascription on ignore:

# (fun _ -> ()) |> (ignore : unit -> _);;
Error: This expression has type unit -> unit
but an expression was expected of type ('a -> unit) -> 'b
Type unit is not compatible with type 'a -> unit

Cheers, Josh

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-07 11:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-09 11:49 [Caml-list] ignore in postfix position Gerd Stolpmann
2018-02-07 11:09 ` Josh Berdine

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).