caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <bhurt@spnz.org>
To: skaller <skaller@users.sourceforge.net>
Cc: Nicolas Cannasse <warplayer@free.fr>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Why doesn't ocamlopt detect a missing ; after failwith statement?
Date: Fri, 26 Nov 2004 13:16:17 -0600 (CST)	[thread overview]
Message-ID: <Pine.LNX.4.44.0411261304140.28854-100000@localhost.localdomain> (raw)
In-Reply-To: <1101427906.9291.107.camel@pelican.wigram>

On 26 Nov 2004, skaller wrote:

> On Fri, 2004-11-26 at 08:14, Nicolas Cannasse wrote:
> > > All well and good, but I don't understand why it doesn't warn me about
> > > the missing ';' in the first case.
> > 
> > val failwith : string -> 'a
> > 
> > so failwith "error" prerr_endline "OK";
> > 
> > is a valid call since 'a unify with (string -> unit) -> string -> unit
> 
> .. a problem which could not occur were there a void type
> which couldn't unify with 'a, and prerr_endline had
> type string-> void.
> 
> 

There is one- it's called unit.  And prerr_endline probably already uses
it. The problem isn't with prerr_endline, the "problem" is with failwith.

failwith needs to return 'a, as it doesn't return.  If it returned some 
other type, I couldn't write code like:
    if some_test then
        failwith "some_test"
    else
        some_value

To make the above expression type correctly, failwith has to return the 
same type as some_value- which could be anything.  Therefor, failwith 
needs to return 'a, a value which can unify with (be the same type as) 
anything else.

The next problem comes in how Ocaml decides when and to what to apply 
arguments.  Consider the expression:
    f [1;2;3]
Fairly obvious, right?  We're calling f with an argument of an int list.  
Not necessarily.  Consider:
    List.map f [1;2;3]
Now f, instead of being the function we're passing arguments into, is now 
an argument itself.

So now, this is exactly the problem we're running into- prerr_endling is 
being treated exactly like f above- one minor change, and it's getting 
turned into an argument when it's meant to be a function call.

Does this help?

Brian



  parent reply	other threads:[~2004-11-26 19:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-25 20:46 Richard Jones
2004-11-25 21:14 ` [Caml-list] " Nicolas Cannasse
2004-11-26  0:11   ` skaller
2004-11-26  0:44     ` Jacques Garrigue
2004-11-26  3:08       ` skaller
2004-11-26  5:25         ` Jacques Garrigue
2004-11-26  7:08           ` Nicolas Cannasse
2004-11-26 14:42             ` Jacques Garrigue
2004-11-26 17:01               ` Alain Frisch
2004-11-26 19:36             ` Michal Moskal
2004-11-26 17:01           ` Damien Doligez
2004-11-29  0:40             ` Jacques Garrigue
2004-11-29 11:07               ` [Caml-list] Why doesn't ocamlopt detect a missing ; afterfailwith statement? Frederic van der Plancke
2004-11-29 11:43                 ` Jacques Garrigue
2004-11-29 11:27               ` Frederic van der Plancke
2004-11-26 22:24           ` [Caml-list] Why doesn't ocamlopt detect a missing ; after failwith statement? Hendrik Tews
2004-11-27  3:47             ` skaller
2004-11-29  0:01             ` Jacques Garrigue
2004-11-29  7:52               ` Marcin 'Qrczak' Kowalczyk
2004-11-26  3:58       ` skaller
2004-11-26 19:16     ` Brian Hurt [this message]
2004-11-26  9:01   ` Richard Jones
2004-11-26  9:56     ` skaller
2004-11-26 13:32     ` Ville-Pertti Keinonen

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=Pine.LNX.4.44.0411261304140.28854-100000@localhost.localdomain \
    --to=bhurt@spnz.org \
    --cc=caml-list@inria.fr \
    --cc=skaller@users.sourceforge.net \
    --cc=warplayer@free.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).