Browse thread
[Caml-list] How to read three integers from a text-file... ?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2002-05-03 (22:21) |
From: | Dave Berry <daveb@t...> |
Subject: | Re: [Caml-list] How to read three integers from a text-file... ? |
At 14:20 30/04/2002, Francois Pottier wrote: >The function that concatenates CPS-encoded tuples is as follows: > > let (++) tuple1 tuple2 k = > tuple2 (tuple1 k) > >A simple ``tuple'' that contains one integer (read from standard input >when the tuple is queried) is > > let int k = > k (int_of_string (input_line stdin)) Neat. In practice you'd want to thread the input stream (or possibly the input operation) through the combinators. >You can then read, say, three integers from standard input and compute >something out of them in the following way: > > (int ++ int ++ int) (fun x y z -> x + y * z) Perhaps it would be neat to have some syntactic sugar for this, e.g.: bind <pat> = <exp1> in <exp2> end as sugar for <exp1> (fun <pat> -> <exp2>) (This is simply the opposite application order from the expansion of "let" bindings: let <pat> = <exp1> in <exp2> end is sugar for (fun <pat> -> <exp2>) (<exp1>). Of course, the types are different, and "let" bindings also generalise type variables). Dave.] ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners