> > Thanks Alex, > > that did the trick (and thanks for the pointer on pure and impure). > > However, now I've stumbed across a second problem, I've implemented > writeToFile as > > "writeToFile", > (p2 (fun file str -> > let value = > try > let oc = open_out (unbox_string file) in > output_string oc (unbox_string str); > flush oc; > close_out oc; > "write success" > with e -> > raise e > in > box_string value), > datatype "(String, String) ~> ()", > IMPURE); > > Which seems to work fine for writing a file. In an editor the file looks > normal, but when Links parses the file I get a syntax error at the end of > the first line. As an experiment I deleted all the new lines and tabs, and > then the syntax error disappeared. I guess this is because Links' Strings > are stored explicitly with the newlines and tabs? Is there a way to escape > this? Any ideas? > > On Mon, Mar 8, 2010 at 6:44 AM, Alexander Ulrich < > [email protected]> wrote: > >> 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 >> >> >> _______________________________________________ >> links-users mailing list >> [email protected] >> http://lists.inf.ed.ac.uk/mailman/listinfo/links-users >> >> >
_______________________________________________ links-users mailing list [email protected] http://lists.inf.ed.ac.uk/mailman/listinfo/links-users
