Hi Simon,
On 3/8/10 1:33 AM, Simon Vansintjan wrote:
> Hey Sam, I've been trying to read the first 100 lines from a file with the
> following code (hoping to replace the 100 with some way to count how large a
> file is - which is another thing I have been having issues with)
>
> "readFromFile",
> (p1 (fun file ->
> let value =
> let ic = open_in (unbox_string file)
> and buf = "" in
> really_input ic buf 0 100;
> buf
> in
> box_string buf),
>
> datatype "(String) ~> (String)",
> PURE);
>
> which compiles fine, but when I run it in Links I get the following error:
>
> *** Error: Invalid_argument("really_input")The length of the string "buf" must correspond to the number of bytes you want to read into it. You can't read 100 bytes into a string of length 0. "Raise Invalid_argument "really_input" if pos and len do not designate a valid substring of buf." (OCaml stdlib reference). and buf = String.create 100 in Besides, your function "readFromFile" has certainly no SQL equivalent and should therefore be marked IMPURE. Alex
signature.asc
Description: OpenPGP digital signature
_______________________________________________ links-users mailing list [email protected] http://lists.inf.ed.ac.uk/mailman/listinfo/links-users
