* beginners list
@ 2007-02-24 18:43 christian konrad
2007-02-24 18:59 ` [Caml-list] " Richard Jones
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: christian konrad @ 2007-02-24 18:43 UTC (permalink / raw)
To: caml-list
Hello again,
I just signed up to the beginners with the message: "/Your membership to
the ocaml_beginners mailing list is waiting for the moderator's approval."
/so for a last time I misuse this list, sorry. I wrote this piece of code:
type ergebnis = {teamid1: int; teamid2: int; goals1: int; goals2: int};;
type spieltag = {number: int; ergebnisse: ergebnis list};;
...
let rec readSpieltagelist filehandle numberofgames =
let createErgebnis tid1 tid2 g1 g2 =
{teamid1=tid1; teamid2=tid2; goals1=g1; goals2=g2;}
in
let rec readErgebnisse fh number =
match number with
| 0 -> []
| n -> let line = (input_line fh) in (Scanf.sscanf line
"%d\t%d\t%d\t%d" createErgebnis):: (readErgebnisse fh (number-1));
in
try
let spieltag = int_of_string(read_line filehandle) in
let ergebnislist = (readErgebnisse filehandle numberofgames) in
{number=spieltag; ergebnisse=ergebnislist;} ::
(readSpieltagelist filehandle numberofgames);
with End_of_file -> [];;
with the hope to read from a file informations like:
1
1 2 3 4
3 2 1 6
4 2 1 9
2
1 4 9 2
3 2 1 9
9 1 2 3
3
...
I would call: readSpieltagelist filehandle 3
in that case.
This code doesn't compile, I get an error with the variable filehandle
in this expression:
let ergebnislist = (readErgebnisse filehandle numberofgames) in
"This expression has type unit but is here used with type in_channel"
Why that?? I really do not understand that. Do I use "filehandle"
somewhere as a unit type? Where, why?
Thanks for help,
chris
//
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] beginners list
2007-02-24 18:43 beginners list christian konrad
@ 2007-02-24 18:59 ` Richard Jones
2007-02-24 19:19 ` micha
2007-02-25 1:03 ` Jon Harrop
2 siblings, 0 replies; 4+ messages in thread
From: Richard Jones @ 2007-02-24 18:59 UTC (permalink / raw)
To: christian konrad; +Cc: caml-list
On Sat, Feb 24, 2007 at 01:43:31PM -0500, christian konrad wrote:
> Hello again,
>
> I just signed up to the beginners with the message: "/Your membership to
> the ocaml_beginners mailing list is waiting for the moderator's approval."
> /so for a last time I misuse this list, sorry. I wrote this piece of code:
Christian, I've approved you for the beginners list now.
Rich.
--
Richard Jones
Red Hat UK Limited
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] beginners list
2007-02-24 18:43 beginners list christian konrad
2007-02-24 18:59 ` [Caml-list] " Richard Jones
@ 2007-02-24 19:19 ` micha
2007-02-25 1:03 ` Jon Harrop
2 siblings, 0 replies; 4+ messages in thread
From: micha @ 2007-02-24 19:19 UTC (permalink / raw)
To: christian konrad; +Cc: caml-list
christian konrad wrote:
> Hello again,
>
>
> Why that?? I really do not understand that. Do I use "filehandle"
> somewhere as a unit type? Where, why?
>
read_line reads from stdin and expects type unit as parameter (you want
to use input_line)
Michael
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] beginners list
2007-02-24 18:43 beginners list christian konrad
2007-02-24 18:59 ` [Caml-list] " Richard Jones
2007-02-24 19:19 ` micha
@ 2007-02-25 1:03 ` Jon Harrop
2 siblings, 0 replies; 4+ messages in thread
From: Jon Harrop @ 2007-02-25 1:03 UTC (permalink / raw)
To: caml-list
On Saturday 24 February 2007 18:43, christian konrad wrote:
> (Scanf.sscanf line "%d\t%d\t%d\t%d" createErgebnis) ::
> (readErgebnisse fh (number-1));
I think you've made exactly the same mistake here. Also, the outer brackets
are superfluous. You probably want:
let line = Scanf.sscanf line "%d\t%d\t%d\t%d" createErgebnis in
line :: readErgebnisse fh (number-1)
but it depends whether you wanted to recurse first or read a line first (I
can't tell from your code and neither can the compiler).
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-02-25 1:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-24 18:43 beginners list christian konrad
2007-02-24 18:59 ` [Caml-list] " Richard Jones
2007-02-24 19:19 ` micha
2007-02-25 1:03 ` Jon Harrop
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox