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
type error: converting input channel to string list
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1997-03-14 (18:21)
From: Pierre Weis <Pierre.Weis@i...>
Subject: Re: type error: converting input channel to string list
> let string_list_of_chann chann =
>   let rec slof_aux (ch: in_channel) (l: string list) = 
>     try
>       let readstr = input_line ch in
>       slof_aux ch readstr::l
>     with End_of_file -> l
>   in slof_aux chann []
> and the error is:
> File "query.ml", line 11, characters 19-155:
> This expression has type in_channel -> string list -> string list
> but is here used with type in_channel -> string -> string
> make: *** [all] Error 2
> Is this a problem with relying on an exception to type a function?

No, your problem is just parsing: you should write

 slof_aux ch (readstr::l) instead of slof_aux ch readstr::l

since in Caml, function application binds tighter than operations,
that is, for all binary infix operator op

f x op z means (f x) op z

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/