Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] strange message
@ 2001-03-14 19:57 Antoine Marin
  2001-03-14 20:36 ` Antoine Marin
  2001-03-14 21:23 ` Michel Quercia
  0 siblings, 2 replies; 3+ messages in thread
From: Antoine Marin @ 2001-03-14 19:57 UTC (permalink / raw)
  To: Caml list

Sorry for this question, but I don't understand why I get this message for this
small programme :

------- Programme
(*
 * Reverse a file by line
 *)

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);;

let main =
  let chan_len = in_channel_length stdin in
  let str_buf = String.create (chan_len + 1) in
  let junk = input stdin str_buf 1 chan_len in
  str_buf.[0] <- '\n';
  rev_write str_buf chan_len chan_len;;
------- Message

File "reverse_line_file.ml", line 11, characters 2-199:
The type of this expression, '_a,
contains type variables that cannot be generalized

-------

I don't understand either the 'characters 2-199' message.

NOTE: commenting the call to 'rev_write' in 'main' make this message disappear
(but it does nothing of course ...).

Thanx,

Antoine
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] strange message
  2001-03-14 19:57 [Caml-list] strange message Antoine Marin
@ 2001-03-14 20:36 ` Antoine Marin
  2001-03-14 21:23 ` Michel Quercia
  1 sibling, 0 replies; 3+ messages in thread
From: Antoine Marin @ 2001-03-14 20:36 UTC (permalink / raw)
  To: Caml list

Antoine Marin a écrit :
> 
> Sorry for this question, but I don't understand why I get this message for this
> small programme :

...

I had the answer from Xavier Rival, thank you

Antoine
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] strange message
  2001-03-14 19:57 [Caml-list] strange message Antoine Marin
  2001-03-14 20:36 ` Antoine Marin
@ 2001-03-14 21:23 ` Michel Quercia
  1 sibling, 0 replies; 3+ messages in thread
From: Michel Quercia @ 2001-03-14 21:23 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-03-14 20:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-14 19:57 [Caml-list] strange message Antoine Marin
2001-03-14 20:36 ` Antoine Marin
2001-03-14 21:23 ` Michel Quercia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox