English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Type inference problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-11-01 (16:17)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] Type inference problem

On Tue, 1 Nov 2005, 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).

A general tactic I use in cases like this is to add type annotations. 
What is almost certainly happening is that somewhere else before this line 
in your code you are returning unit as a value, so Ocaml thinks it's 
supposed to return unit.  If you add a type annotation to explicitly state 
that it returns int, Ocaml will instead give an error where you return 
unit, allowing you to fix the problem.