Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] strange message
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michel Quercia <quercia@c...>
Subject: Re: [Caml-list] strange message
Le Wed, 14 Mar 2001, vous [Antoine Marin] avez écrit :
> Sorry for this question, but I don't understand why I get this message for this
> small programme :

> let rec rev_write str_buf str_len str_pos = match str_buf.[str_pos] with
>   | '\n' -> output stdout str_buf (str_pos + 1) (str_len - str_pos);
>     rev_write str_buf str_len (str_pos - 1);
>   | _ -> rev_write str_buf str_len (str_pos - 1);;

Cette fonction boucle. Le compilateur attribue à rev_write le type
string -> int -> int -> 'a ce qui signifie que le résultat est indéterminé.
Voici un code correct :

let rec rev_write str_buf str_len str_pos =
  if str_len > 0 then
    match str_buf.[str_pos] with
      | '\n' -> output stdout str_buf (str_pos + 1) (str_len - str_pos);
                rev_write str_buf str_pos (str_pos - 1);
      | _ -> rev_write str_buf str_len (str_pos - 1)
;;

-- 
Michel Quercia
57 rue abbé Grégoire, 38000 Grenoble
http://pauillac.inria.fr/~quercia
mailto:michel.quercia@prepas.org
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr