Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: -- (:)
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.
> jonathan@moonbeam:~/dst/stdlib$ ocamlc
> File "", 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.