* [Caml-list] ignore semantics
@ 2012-12-17 12:11 Philippe Veber
2012-12-17 13:32 ` John Whitington
2012-12-18 1:28 ` Francois Berenger
0 siblings, 2 replies; 4+ messages in thread
From: Philippe Veber @ 2012-12-17 12:11 UTC (permalink / raw)
To: caml users
[-- Attachment #1: Type: text/plain, Size: 595 bytes --]
Dear all,
This is a rather minor issue, but I was surprised by the following answers
of the interpreter:
OCaml version 4.00.1
# ignore succ;;
Warning 5: this function application is partial,
maybe some arguments are missing.
- : unit = ()
# (fun _ -> ()) succ;;
- : unit = ()
I naively used to think the two expressions were equivalent. Reading
pervasives.mli, I found that ignore is a primitive:
external ignore : 'a -> unit = "%ignore"
which means it is treated as a special case. Just for curiosity, what is
the rationale for the warning in the first case?
Cheers,
Philippe.
[-- Attachment #2: Type: text/html, Size: 1429 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] ignore semantics
2012-12-17 12:11 [Caml-list] ignore semantics Philippe Veber
@ 2012-12-17 13:32 ` John Whitington
2012-12-18 13:41 ` Philippe Veber
2012-12-18 1:28 ` Francois Berenger
1 sibling, 1 reply; 4+ messages in thread
From: John Whitington @ 2012-12-17 13:32 UTC (permalink / raw)
To: Philippe Veber; +Cc: caml users
Hi,
Philippe Veber wrote:
> This is a rather minor issue, but I was surprised by the following
> answers of the interpreter:
>
> OCaml version 4.00.1
>
> # ignore succ;;
> Warning 5: this function application is partial,
> maybe some arguments are missing.
> - : unit = ()
> # (fun _ -> ()) succ;;
> - : unit = ()
>
> I naively used to think the two expressions were equivalent. Reading
> pervasives.mli, I found that ignore is a primitive:
>
> external ignore : 'a -> unit = "%ignore"
>
> which means it is treated as a special case. Just for curiosity, what is
> the rationale for the warning in the first case?
Imagine you wrote:
ignore (output_something_and_return_something)
When what you wanted was
ignore (ouput_something_and_return_something ())
You'd want the partial application error there, even though you are
(intentionally) ignoring the return value of the function.
Cheers,
--
John Whitington
Director, Coherent Graphics Ltd
http://www.coherentpdf.com/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] ignore semantics
2012-12-17 12:11 [Caml-list] ignore semantics Philippe Veber
2012-12-17 13:32 ` John Whitington
@ 2012-12-18 1:28 ` Francois Berenger
1 sibling, 0 replies; 4+ messages in thread
From: Francois Berenger @ 2012-12-18 1:28 UTC (permalink / raw)
To: caml-list
On 12/17/2012 09:11 PM, Philippe Veber wrote:
> Dear all,
>
> This is a rather minor issue, but I was surprised by the following
> answers of the interpreter:
>
> OCaml version 4.00.1
>
> # ignore succ;;
> Warning 5: this function application is partial,
> maybe some arguments are missing.
> - : unit = ()
> # (fun _ -> ()) succ;;
> - : unit = ()
Didn't you intended to write
ignore (succ 0);;
(or with any other integer instead of 0) ?
In that case it compiles but I don't get what the code
is intended to do.
Regards,
F.
> I naively used to think the two expressions were equivalent. Reading
> pervasives.mli, I found that ignore is a primitive:
>
> external ignore : 'a -> unit = "%ignore"
>
> which means it is treated as a special case. Just for curiosity, what is
> the rationale for the warning in the first case?
>
> Cheers,
> Philippe.
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] ignore semantics
2012-12-17 13:32 ` John Whitington
@ 2012-12-18 13:41 ` Philippe Veber
0 siblings, 0 replies; 4+ messages in thread
From: Philippe Veber @ 2012-12-18 13:41 UTC (permalink / raw)
To: John Whitington; +Cc: caml users
[-- Attachment #1: Type: text/plain, Size: 1224 bytes --]
Hi John,
That's a good reason indeed, good enough to justify having this special
case semantics. Thanks!
ph.
2012/12/17 John Whitington <john@coherentgraphics.co.uk>
> Hi,
>
>
> Philippe Veber wrote:
>
>> This is a rather minor issue, but I was surprised by the following
>> answers of the interpreter:
>>
>> OCaml version 4.00.1
>>
>> # ignore succ;;
>> Warning 5: this function application is partial,
>> maybe some arguments are missing.
>> - : unit = ()
>> # (fun _ -> ()) succ;;
>> - : unit = ()
>>
>> I naively used to think the two expressions were equivalent. Reading
>> pervasives.mli, I found that ignore is a primitive:
>>
>> external ignore : 'a -> unit = "%ignore"
>>
>> which means it is treated as a special case. Just for curiosity, what is
>> the rationale for the warning in the first case?
>>
>
> Imagine you wrote:
>
> ignore (output_something_and_return_**something)
>
> When what you wanted was
>
> ignore (ouput_something_and_return_**something ())
>
> You'd want the partial application error there, even though you are
> (intentionally) ignoring the return value of the function.
>
> Cheers,
>
> --
> John Whitington
> Director, Coherent Graphics Ltd
> http://www.coherentpdf.com/
>
>
[-- Attachment #2: Type: text/html, Size: 1907 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-12-18 13:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-17 12:11 [Caml-list] ignore semantics Philippe Veber
2012-12-17 13:32 ` John Whitington
2012-12-18 13:41 ` Philippe Veber
2012-12-18 1:28 ` Francois Berenger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox