* type error: converting input channel to string list
@ 1997-03-14 1:25 Lyn A Headley
1997-03-14 18:20 ` Pierre Weis
0 siblings, 1 reply; 2+ messages in thread
From: Lyn A Headley @ 1997-03-14 1:25 UTC (permalink / raw)
To: caml-list
hi all,
I can't seem to make sense of this type error. Sorry to air my
dirty laundry but I was hoping I could get some assistance with this
one, as I am stumped.
the code is merely:
(* turn an input channel into a list of strings *)
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?
thanks,
Lyn
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: type error: converting input channel to string list
1997-03-14 1:25 type error: converting input channel to string list Lyn A Headley
@ 1997-03-14 18:20 ` Pierre Weis
0 siblings, 0 replies; 2+ messages in thread
From: Pierre Weis @ 1997-03-14 18:20 UTC (permalink / raw)
To: Lyn A Headley; +Cc: caml-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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-03-14 18:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-14 1:25 type error: converting input channel to string list Lyn A Headley
1997-03-14 18:20 ` Pierre Weis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox