... Hi, 'a option is a predefined type, which is absolutely not magic and certainly not a keyword. You could have defined it by yourself, but this one is...
I found there are codes as follows: let outChannel : out_channel option ref = ref None let mergedChannel : out_channel option ref = ref None Here, "option" is...
... No, not at all. Having 'out_channel option' rather than ''a option' just means that the type is completely specified. If you were to specify 'a option in a...
... The types are read backwards. Example: int list is a list of integers int option list is a list of optional integers int list option is an optional...
... It means "evaluate 'bla' now". In this instance, 'bla' is assumed to be something which evaluates to / returns '()' (ie. the unit value). There is another...
Hi, all When I define some record variables in toplevel, it can interactively give out the details of these variables. For example, # type myrec = { fld1 :...
... Well, one way to do it is to create a printer for each class and use #install_printer to get the effect you want. For example, with the point class you...
Hello all, There are two functions [f] and [g] defined as: let f n = match n with ... let g n = match n with ... When I employ [try with] as follows, (* --Ver...
... It's because your definition ("try f with .....") of h is immediately evaluated (since you gave no argument after the "h"). So it does not fail, and h =...
Hi, ... ^^ this expression computes nothing, thus cannot raise an exception ... This is therefore equivalent to: let h = f And it is (almost) the same as: let...
The following function, does produce a file named [txt], but despite calling it multiple times, the file remains empty. Any possible explaination ??? let...
I have code that works just fine as a module, but as I try to convert it to a class, I'm running into problems with what looks like kprintf and that funky...
... Mmmm... doing a little reading in the OCaml manual at section 3.11, it looks like I might need to define an explicit polymorphic method, but I'm not having...
... Yes, you will probably need to do that. I recommend looking at the [Cf_journal] module in my [Cf] library. It has a treatment of a similar problem. ...
... The syntax for polymorphic methods is not the above. (That's the syntax for a polymorphic class). Try a syntax similar to the map or fold_* methods on...
Hi all, I'm relatively new to Ocaml and I'm still trying to figure out the Ocaml way of doing things. Given a list like : let a = [ "qwe" ; "asd" ; "zxc" ] ;; ...
... <snip> ... String.concat ", " a Anyway, if you are interested in a generic way to concatenate string, it's butter to use the Buffer module which has better...
... Many operations on list can be expressed succinctly by using List.fold_left or List.fold_right: let a = [ "qwe" ; "asd" ; "zxc" ];; let comma_concat l r = ...
... OK, thats really good for lists of strings, but what about arrays of strings? Is this a reasonable method: String.concat ", " (Array.to_list a) Erik...
... Yes, IMO it's reasonable. It would be interesting to compare it with the following approach: let buf = Buffer.create <guess_a_size> in Array.iter...
... The advantage of String.concat is that it copies the characters directly into the result string, not into a temporary buffer (which is himself a string). ...
... Yes, but the other solution has also an additional linear pass on the array to convert it to a string. Probably is better than the buffer solution which...
... You have to copy all these string fragments. To concatenate a list of N strings of length M, List.fold_right ( ^ ) copies a total of 2M + 3M + ... + NM =...