dark_light changed the topic of #ocaml to: OCaml 3.09.2 available! Archive of Caml Weekly News: http://sardes.inrialpes.fr/~aschmitt/cwn/ | A free book: http://cristal.inria.fr/~remy/cours/appsem/ | Mailing List: http://caml.inria.fr/bin/wilma/caml-list/ | Cookbook: http://pleac.sourceforge.net/
smimou has quit ["bli"]
_jol_ has joined #ocaml
kuribas has quit ["ERC Version 5.0.2 $Revision: 1.726.2.10 $ (IRC client for Emacs)"]
chessguy has joined #ocaml
_jol_ has quit ["leaving"]
BetaTEST has quit []
chessguy2 has joined #ocaml
chessguy2 has quit [Client Quit]
sponge45 has joined #ocaml
danly has joined #ocaml
pango__ has joined #ocaml
chessguy has quit [Connection timed out]
Demitar_ has quit [Read error: 113 (No route to host)]
Revision17 has joined #ocaml
sponge45 has quit [Read error: 104 (Connection reset by peer)]
finelemon has joined #ocaml
finelemo1 has quit [Read error: 110 (Connection timed out)]
_JusSx_ has joined #ocaml
_jol_ has joined #ocaml
sponge45 has joined #ocaml
pango__ has quit [Remote closed the connection]
pango__ has joined #ocaml
_jol_ has quit [Read error: 110 (Connection timed out)]
sponge45 has quit ["zzzzzzzz"]
pango__ has quit [Remote closed the connection]
pango__ has joined #ocaml
revision17_ has joined #ocaml
pango has quit [Nick collision from services.]
pango__ is now known as pango
Revision17 has quit [Read error: 110 (Connection timed out)]
mnemonic has joined #ocaml
_jol_ has joined #ocaml
<mnemonic> yo
smimou has joined #ocaml
dark_light has quit ["Ex-Chat"]
_jol_ has quit ["citka temci .i baze'i xruti"]
dark_light has joined #ocaml
<dark_light> i must iterate over a directory. if i use recursive functions and the directory is too large i will get a stack overflow? i am using a while, but that i way i have to go with so many references
<dark_light> the way i am doing is particulary ugly. i am using a try while true do .. with End_of_file
<smimou> dark_light: you won't get a stack overflow if your function is tail-recursive
<dark_light> what is a function tail-recursive? i function like while?
<smimou> while is not recursive
<smimou> you won't get a stack overflow out of it
<dark_light> while can be defined as a recursive function
<smimou> yes, but it isn't in ocaml
<dark_light> hmmm
mnemonic has quit ["leaving"]
<dark_light> trying to read about tail recursion.. right, tail recursion is a recursion that can be easly transformed into a iteration, but i still don't get how to make one..
_jol_ has joined #ocaml
mnemonic has joined #ocaml
<fluxx> dark_light, a function that converts exceptions into values is useful in that one
<fluxx> like: type ('a, 'b) value = Value of 'a | Exception of 'b let valuefy f a = try Value (f a ) with exn -> Exception exn
<dark_light> fluxx, but, should i keep using while?
<fluxx> I wouldn't
<fluxx> then you can write your recursive function as let get_contents handle contents = match valuefy (read_dir) (handle) with Value x -> x::contents | Exception exn -> contents
<fluxx> and you could call that like get_contents (opendir "foo") []
<fluxx> you would want to put that function inside another one which provides the [], plus optionally reverses the list afterwards (you could do that in the get_contents-function too, though)
<dark_light> Hmmm:) it will not raise a stack overflow?
<fluxx> no
<dark_light> nice
<fluxx> uh, I wrote that the wrong way
<fluxx> it should be ..with alue x -> get_contents handle (x::contents) ..
<fluxx> Value even
<fluxx> and the function should be recursive: let rec get_contents ..
<fluxx> if the last thing in the function is another function call, it will not end up into stack overflow
<fluxx> except with exceptions
<fluxx> if you have a handler for them
<fluxx> because it would need to traverse them all when an exception occurs
<dark_light> Hmmm
<fluxx> that is why a technique similar to 'valuefy' is useful
<fluxx> so if one were to naively write let rec get_contents handle contents = try get_contents handle (read_dir handle :: contents) with exn -> contents, it would overflow
<fluxx> too bad, because that would arguably a more natural way to write the function
<dark_light> :o
<dark_light> but
<dark_light> the call of get_contents
<dark_light> isn't the last thing on function
<fluxx> after get_contents, what happens?
<dark_light> Value x is before Exception exn
<dark_light> you mean, can't have a ; after get_contents?
<fluxx> it is the last thing in that control flow
<dark_light> hm
<fluxx> after get_contents the next evaluated thing would be the end of the function
Demitar has joined #ocaml
<dark_light> ah
<fluxx> that is: the return value of the function would be determined by what get_contents returns
<fluxx> which is why it is possible to eliminate the current function from the call stack
<dark_light> :o
<fluxx> note that not all call flows need to be candidates to tail call optimization
<fluxx> there could be another branch which would not be tail-recursive, and infact, for example the call for valuefy and read_dir, are such calls
_jol_ has quit ["temci lo nu taxfu lumci"]
kuribas has joined #ocaml
<kuribas> Hi, why cann't I use the Set library from the interpreter?
<pango> seems to work ok... module StringSet = Set.Make(struct type t = string let compare = String.compare end) ...
<pango> # StringSet.add "hello" StringSet.empty ;;
<pango> - : StringSet.t = <abstr>
<pango> (actually I could have used module StringSet = Set.Make(String) ...)
<kuribas> I see. How can I make a set from a tuple (int * int)?
<pango> you also need to provide a compare function over your tuples
<kuribas> Doesn't there already exist a compare function for tuples?
<pango> well, Pervasives.compare is polymorphic, so it should work (whether it gives what you expect depends on what you expect ;) )
<pango> # module OrderedTuples = struct
<pango> type t = int * int
<pango> let compare (a:t) (b:t) = compare a b
<pango> end ;;
<pango> # module TupleSet = Set.Make(OrderedTuples) ;;
<kuribas> I think compare will be fine.
mnemonic has quit ["leaving"]
<pango> yes, I think it gives lexicographic comparison
<pango> ie let compare (a1,b1) (a2,b2) = let cmp = compare a1 a2 in if cmp <> 0 then cmp else compare b1 b2
<kuribas> Yes, that's nice. Haskell has that too for tuples and lists.
<kuribas> This seems to work:
<kuribas> # module TupleSet = Set.Make( struct type t = int * int;; let compare = compare end);;
<pango> however lexicographic is far from being the only total ordering over tuples
<pango> must be ; instead of ;; after type t I guess
<pango> ;; separate "sentenses", when it cannot be inferred (or, at repl level, to trigger evaluation)
<kuribas> I tried ; first, but it gave me a syntax error.
<pango> mmh in fact it should be nothing, not ; ... and strangely, it indeed doesn't complain about ;; ... strange)
<pango> it correctly inferred the type of compare too (t -> t -> int), in this context... good
<kuribas> Haskell can infer the type of Set also, so I don't need to give a module declaration.
<kuribas> That was why I was confused that it didn't work.
<pango> it remains that ;; should be used between sentenses only, when back to "toplevel"; It can often be totally omitted in compiled modules, but some people like to use them in compiled programs too
<kuribas> So there is no need to use ;; in a ocaml sourcefile?
<smimou> no
<kuribas> All remember that, thanks :)
<pango> kuribas: it's well explained in ocaml-tutorial.org wiki, ;; is inferred automatically before some keywords, like open, type, let, module,...
<pango> so you can write sources without ever using ;; if you want, just sometimes using let _ = instead
<kuribas> I didn't know about ocaml-tutorial.org. I learned ocaml from "Introduction to the Objective Caml Programming Language" by Jason Hickey.
<pango> personally I mainly learned using "developing applications with objective caml"
<pango> but ocaml-tutorial is the first place where I read a clear explanation on the use of ;;
slipstream-- has joined #ocaml
dark_light has quit [No route to host]
slipstream has quit [Connection timed out]
ulfdoz has quit [Remote closed the connection]
ulfdoz has joined #ocaml
<lde> Is there some easier way of writing (function x -> Some x)?
<zmdkrbou> s/function/fun
<zmdkrbou> +/
<zmdkrbou> (and no)
<lde> I thought so. Thanks.
<Smerdyakov> zmdkrbou, but isn't using 'fun' easier? :)
_jol_ has joined #ocaml
_jol_ has quit ["leaving"]
Smerdyakov has quit ["Leaving"]
mnemonic has joined #ocaml
<mnemonic> hi
Snark has joined #ocaml
tristram has quit [Read error: 110 (Connection timed out)]
Smerdyakov has joined #ocaml
Snark has quit ["Leaving"]
kuribas has quit [clarke.freenode.net irc.freenode.net]
_JusSx_ has quit [clarke.freenode.net irc.freenode.net]
finelemon has quit [clarke.freenode.net irc.freenode.net]
lde has quit [clarke.freenode.net irc.freenode.net]
dvekravy has quit [clarke.freenode.net irc.freenode.net]
fluxx has quit [clarke.freenode.net irc.freenode.net]
dvekravy has joined #ocaml
finelemon has joined #ocaml
_JusSx_ has joined #ocaml
kuribas has joined #ocaml
rillig has joined #ocaml
jacobolus has joined #ocaml
flux__ has joined #ocaml
jacobolus has quit [Read error: 104 (Connection reset by peer)]
jacobolus_ has joined #ocaml
mnemonic has quit ["leaving"]
jacobolus_ has quit []
rillig has quit ["exit(EXIT_SUCCESS)"]
_JusSx_ has quit ["leaving"]
malc_ has joined #ocaml
flux__ has quit [clarke.freenode.net irc.freenode.net]
flux__ has joined #ocaml
flux__ has quit [clarke.freenode.net irc.freenode.net]
smimou has quit ["bli"]
flux__ has joined #ocaml