caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Jonathan Roewen <jonathan.roewen@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Type inference problem
Date: Tue, 01 Nov 2005 19:50:07 +1100	[thread overview]
Message-ID: <1130835007.7552.88.camel@rosella> (raw)
In-Reply-To: <ad8cfe7e0511010019n3a17eb89y291496eb95eb0163@mail.gmail.com>

On Tue, 2005-11-01 at 21:19 +1300, Jonathan Roewen wrote:
> Ohh, I found it =) If without else, where return type of if is non-unit.
> 
> Is it possible compiler could flag this error a bit better? IE: when
> if returns non-unit, and there's no else?

Ocaml uses some shortcuts because it doesn't distinguish
functional from procedural code.

Felix does. It uses:

	if c1 then e1 [elif c2 then e2 ..] else ee endif

for functional code -- the 'else' is mandatory, and the expressions
e1, e2 .. ee may not be void, and must unify.

Procedural code uses

	if c do 
		... ; ... ; 
	[elif
		... ; ... ;
	..
	]

	[else
		..; .. ; 
	]
	done;

and all the ... ; entries must be (manifestly) of type void.


Now, the problem with your request is that Ocaml is
*deducing* the type of read .. it is in fact unit, so the
condition for reporting an error you state would NOT catch
any error because there isn't one.

On the other hand if you obey a reasonable style rule:

"always annotate the return type of a recursive function"

then Ocaml would have done precisely what you asked for.
Whenever you get a type error you don't understand
*add type annotations* to try to localise the problem.

I would restate your request like this: when the inference
engine reports a type error, it should provide a full traceback
of all parts of the code that lead it to deduce the conflicting
types.

I expect the error message would be hard to read.. and also that
it would greatly complicate the inference engine to actually
keep track of where all the inferences come from -- not sure
on either point.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2005-11-01  8:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-01  7:58 Jonathan Roewen
2005-11-01  8:19 ` Jonathan Roewen
2005-11-01  8:50   ` skaller [this message]
2005-11-01  8:34 ` skaller
2005-11-01 16:21 ` Brian Hurt
  -- strict thread matches above, loose matches on Subject: below --
2001-06-28 15:23 Vasilij Karpow
2001-06-28 15:40 ` Remi VANICAT
2001-06-28 19:08 ` Nils Goesche
2001-06-29  2:41 ` Jacques Garrigue

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=1130835007.7552.88.camel@rosella \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@yquem.inria.fr \
    --cc=jonathan.roewen@gmail.com \
    /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).