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:34:25 +1100 [thread overview]
Message-ID: <1130834065.7552.71.camel@rosella> (raw)
In-Reply-To: <ad8cfe7e0510312358qb5d7fd5s78f3487ce9fac6f7@mail.gmail.com>
On Tue, 2005-11-01 at 20:58 +1300, Jonathan Roewen wrote:
> Hi,
>
> I can't figure out what's wrong with my code =(
>
> It's on a paste site, so will only last about 24 hours or so.
> http://rafb.net/paste/results/Uux57B97.html
>
> jonathan@moonbeam:~/dst/stdlib$ ocamlc VFS.ml
> File "VFS.ml", line 106, characters 3-6:
> This expression has type int but is here used with type unit
>
> It -has- to return int ;-) But I have no idea where the type
> constraint is coming from that wants it to return unit. Change it to
> return unit, and where it's used complains it doesn't return type int
> (so that constraint is correct).
You could replace this line:
let rec write data fd buf off len =
with this one:
let rec write data fd buf off len : int =
to find out. But I can tell you anyhow the bug is here
let rec read data fd buf off len =
if len + fd.offset > fd.size then read data fd buf off (fd.size - fd.offset);
in the second line:
if true then 1;
will give the same error for the same reason: the above line is just
shorthand for:
if true then 1 else ();
and the type of 1 and () disagree. In your case, the type of the 'then'
branch is infered to be 'unit' .. and then you go and return
an 'int' at the end of the function -- there is no 'conflict'
until that point. Declaring the return type will catch the
error where it really is, the second line of the read function.
You can fix this by:
if len + fd.offset > fd.size then
ignore(read data fd buf off (fd.size - fd.offset));
or by
if len + fd.offset > fd.size then
let _ = read data fd buf off (fd.size - fd.offset) in ();
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
next prev parent reply other threads:[~2005-11-01 8:34 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
2005-11-01 8:34 ` skaller [this message]
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=1130834065.7552.71.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).