kaustuv changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | 3.11.1 out now! Get yours from http://caml.inria.fr/ocaml/release.html
slash_ has quit [Client Quit]
thrasibule has quit ["No Ping reply in 90 seconds."]
thrasibule has joined #ocaml
thrasibule has quit ["No Ping reply in 90 seconds."]
thrasibule has joined #ocaml
thrasibule has quit [Read error: 104 (Connection reset by peer)]
thrasibule has joined #ocaml
psnively has joined #ocaml
bzzbzz has quit ["leaving"]
psnively has quit []
thrasibule has quit ["No Ping reply in 90 seconds."]
thrasibule has joined #ocaml
thrasibule_ has joined #ocaml
thrasibule has quit [Read error: 104 (Connection reset by peer)]
thrasibule_ has quit ["No Ping reply in 90 seconds."]
thrasibule has joined #ocaml
thrasibule has quit ["No Ping reply in 90 seconds."]
thrasibule has joined #ocaml
thrasibule has quit [Read error: 104 (Connection reset by peer)]
mishok13 has joined #ocaml
Anarchos has joined #ocaml
Demitar has joined #ocaml
Anarchos has quit ["Vision[0.9.7-H-090423]: i've been blurred!"]
rwmjones has joined #ocaml
LeCamarade|Away is now known as LeCamarade
Snark has joined #ocaml
hkBst has joined #ocaml
Snark has quit ["Ex-Chat"]
Anarchos has joined #ocaml
kaustuv has quit [Remote closed the connection]
kaustuv has joined #ocaml
kaustuv has quit [Read error: 104 (Connection reset by peer)]
Cromulent has joined #ocaml
Beelsebob has quit ["Leaving."]
Beelsebob has joined #ocaml
mattam has quit [Remote closed the connection]
mattam has joined #ocaml
Cromulent has quit []
Spiwack has joined #ocaml
_andre has joined #ocaml
Cromulent has joined #ocaml
th1_ has joined #ocaml
<Anarchos> who uses ocamlyacc ?
<flux> I've used it, but switched to menhir
<Anarchos> flux i noticed that ocamlyacc accept ocaml keywords as non terminal symbols thus generating compiling error afterwards
<flux> I haven't noticed that. I've parsed pretty non-programming-language-like content..
<flux> maybe you can just pick other symbols?
bernardofpc has quit [Remote closed the connection]
<Anarchos> flux yes i change it but it would be wise to forbid ocaml keywords
philed has joined #ocaml
<philed> Hey guys. From reading, I understand that Ocaml exceptions are often used for non-local control. What are the recommendations for this? Would it be typical to raise an exception to bail out of a loop early as you would use break in the C family?
<Anarchos> philed it is pretty rare to need exception to break out of a loop.
<philed> I'm just writing a function which tests whether every element of an array satisfies some predicate. I'm using Array.iter and throwing an exception as soon as I find one that doesn't.
<flux> indeed, breaking early out of the provided high level primitives is impossible otherwise
<flux> especially annoying it is with Map, where you can't easily implement your own iteration
Amorphous has quit [Read error: 104 (Connection reset by peer)]
bombshelter13_ has joined #ocaml
jimmyb2187 has left #ocaml []
<wysek> philed: ... it's not really typical to use loops in ocaml :>
jimmyb2187 has joined #ocaml
Amorphous has joined #ocaml
kaustuv has joined #ocaml
* thelema is surprised there isn't a List.first primitive in ocaml - given a list and a predicate, returns the first element of that list matching the predicate and the rest of the list
<flux> is there in batteries?-)
<kaustuv> let rec first fn = function [] -> failwith "first" | x :: l when fn x -> (x, l) | _ :: l -> first fn l ;;
<flux> I wonder though how useful that would be. if you wanted to process further elements, you'd still have to write a loop.
<kaustuv> there is List.filter_map if you need more than one of them
eyda|mon has joined #ocaml
<eyda|mon> how can I check if a file exists?
<kaustuv> Sys.file_exists
<eyda|mon> thank you
thelema_ has joined #ocaml
* thelema_ is surprised there isn't a List.first primitive in ocaml - given a list and a predicate, returns the first element of that list matching the predicate and the rest of the list
<thelema_> Of course this could be generalized to any enumerable collection - returning a continuation or somesuch
<kaustuv> let rec first fn l : 'a * 'a list = if l = [] then failwith "firsT" else let l = Obj.magic l in if fn (fst l) then l else first fn (tl l) ;;
<kaustuv> hmm...
thelema has quit [Read error: 110 (Connection timed out)]
jonafan_ is now known as jonafan
tmaeda has joined #ocaml
thelema_ is now known as thelema
<thelema> kaustuv: wow, that might be really efficient, but it's the ugliest implementation I can think of.
<thelema> it matches the type un-safety of Obj.magic with the general ugliness of tl
<flux> so, it's good then?
<flux> ;)
<kaustuv> it performs 0 allocations!
<kaustuv> and what's wrong with tl?
<thelema> let rec first fn = function [] -> failwith "first" | h :: t when fn h -> (h,t) | _::t -> first fn t
<thelema> I might write first something like this. I see your point about 0 allocations, but worry about Obj.magic as the method to achieve
<kaustuv> it was not a serious suggestion, and I think your irc timed out before you saw my first response which was identical to yours modulo bound variables
<thelema> even with your method of turning 'a list into 'a * 'a list using magic.
<thelema> I didn't see your first solution.
<thelema> couldn't you move the Obj.magic into the [then] branch?
<thelema> let rec first fn = function [] -> failwith "first" | (h :: _) as lst when fn h -> Obj.magic lst | _::t -> first fn t
<kaustuv> you'd still need some type annotations I think
<thelema> if you used the function properly once, the type-checker should figure it out, no?
<thelema> n/m, it could give it too polymorphic a signature, you're right.
<kaustuv> what's the latest on the batteries front anyhow? Is there going to be a first release before Christmas?
<thelema> yes.
<thelema> just like perl 6 will be out before Christmas.
<thelema> maybe not this Christmas. :)
<thelema> but some christmas.
<thelema> Development has slowed, and with David starting his new job, I think I'll be charge of the project for a while.
zw has joined #ocaml
mbishop_ has joined #ocaml
LeCamarade is now known as LeCamarade|Away
<eyda|mon> I'm trying to learn Ocaml. Here's some code: http://pastie.org/585927 I have two questions about it. number 1, it doesn't feel very Ocaml-ish, but rather very imperative. How can I write it so it's more ml like?
eyda|mon has quit [Remote closed the connection]
eyda|mon has joined #ocaml
<eyda|mon> hm, not sure if my question got through, so I will re-ask
<eyda|mon> I'm trying to learn Ocaml. Here's some code: http://pastie.org/585927 I have two questions about it. number 1, it doesn't feel very Ocaml-ish, but rather very imperative. How can I write it so it's more ml like?
<eyda|mon> ok, failwith seems better to use for one thing.
mbishop has quit [Read error: 113 (No route to host)]
Cromulent has quit []
<eyda|mon> duh
<eyda|mon> I'm missing an argument
<flux> so, I suppose failwith is working ok for you?
<flux> you could have a different kind of exception instead of the generic Failure if you wanted
<eyda|mon> failwith will be fine for now
<eyda|mon> Now I have this which works
<eyda|mon> is that OK ocaml though? seems like I'm using imperative programming to do it
zw has left #ocaml []
<flux> it's OK. if you had more conditions you would perhaps refactor it into something different.
<eyda|mon> ok
<eyda|mon> thank you
tmaeda is now known as tmaedaZ
Cromulent has joined #ocaml
<eyda|mon> What module should I use if I want to do directory operations, such as listing *.cue filenames?
mbishop_ is now known as mbishop
<thelema> eyda|mon: Sys gives you a read-directory function
<thelema> Sys.readdir : string -> string array
<thelema> It doesn't glob for you, though.
<thelema> You could filter using Filename.check_suffix
<eyda|mon> thank you
<eyda|mon> maybe this camelhump thing has a glob module, or perhaps that would be a useful module to write and contribute while I'm learning
<thelema> There's no Array.filter builtin, but it's not difficult to grab the code from Batteries.
<eyda|mon> batteries?
<eyda|mon> oh, that's new
<thelema> it's a pain to install without automated help, but it's a great library
<eyda|mon> and I suppose there is no automated help :)
<thelema> there is - godi
<eyda|mon> thank you :)
<eyda|mon> this is the ruby-gem perl-CPAN equivalent for ocaml?
<thelema> eyda|mon: you seem to have come from an OO language - java?
<thelema> eyda|mon: yes, godi is like those.
<eyda|mon> ruby these days actually
<thelema> don't use a class in ocaml if you don't need one.
<eyda|mon> I made some tiny patches for mldonkey ages ago. thought I'd take another look at it again
<thelema> great.
<eyda|mon> any reason I should consider?
rbancroft has quit [Read error: 60 (Operation timed out)]
<thelema> mostly style, but there's a minor performance disadvantage
rbancroft has joined #ocaml
<eyda|mon> ok
<thelema> let main () = process Sys.argv.(1)
<thelema> let process cue_file = if not ( Sys.file...) fail...; if not (Filename.check_...) fail...; ...
<thelema> let () = main () (* executes the main function *)
<eyda|mon> why not main();; ?
<thelema> makes sure main returns unit my way. main();; could return a value.
<eyda|mon> ah ok
<eyda|mon> why do I care if main returns unit?
<thelema> again, minor, stylistic difference.
<eyda|mon> same reason C likes to have main return int?
<eyda|mon> er, or is it void?
<thelema> if it's returning a value, you might get a warning from main();;
<thelema> but if it's returning a value, it'll fail to compile with let () = main ()
<thelema> main shouldn't return a value. the only way to set a return code is with exit
<thelema> C's main returns exit code of the program, which is great for C.
<thelema> ocaml doesn't have a main function (despite emulating it as good practice) - every line of code you write gets run. That said, the code within a function binding doesn't get run until that function is called.
<thelema> so running a [let f () = ...] is really easy, and doesn't do any computation
<thelema> It's sometimes convenient for me to load my config file way at the top of my code, so I can refer to the config data throughout.
philed has quit [Remote closed the connection]
<thelema> If I loaded the config file in main at the bottom of my code, I'd have to pass a configuration object to everything that could use it.
<eyda|mon> hm, useful to konw
<eyda|mon> know
<eyda|mon> how long have you been using ocaml?
<thelema> I started about 9 years ago.
<thelema> ocaml execution is more like a bash script than a C program.
<thelema> the entry point is the top of the file, and each line is "executed" in turn.
amuck_ has joined #ocaml
<eyda|mon> i've been doing exclusivly interpreted programming, so that suits me :)
<thelema> let bindings for functions don't really execute, as they're already compiled into memory, they just become available to later code.
<thelema> it's still good practice to have a single entry point to your main code, instead of requiring archaeological methods to dig the running code out of the not-running code
Snark has joined #ocaml
Cromulent has quit []
<eyda|mon> would be nice if godi was kept seperate and didn't install its own ocaml version
<eyda|mon> or at least have the option. speaking of which, I wonder if I missed one
<thelema> the other option for managing dependencies of batteries is to have the packages for that platform (RPM,DEB) and have that level package manager deal with dependencies.
amuck_ has left #ocaml []
Cromulent has joined #ocaml
<kaustuv> is it possible to use batteries without camlp4? as in, not even having camlp4 installed?
<thelema> probably not, as some of our dependencies require camlp4 to compile.
<thelema> but assuming you dealt with dependencies, you'd still have to modify the findlib to not run the batteries syntax extensions
<kaustuv> hmm... how hard would it be to strip out the sexplib, estring, etc. stuff from batteries and have just the code ma'am?
<thelema> probably not *too* hard. It's something I've thought about doing, and would likely be great for adoption.
<thelema> but it's not the direction that DT intended, nor most of the other developers.
<thelema> s/most/many/
<eyda|mon> what was required to get Array.filter?
<thelema> It's currently implemented using BitSet
<thelema> http://git.ocamlcore.org/cgi-bin/gitweb.cgi?p=batteries/batteries.git;a=tree;f=src/core/extlib;h=9b6eb1f50714f6ad8cc195823a14b7c8b8566449;hb=HEAD
<thelema> go here, d/l BitSet.ml* and then copy the function from extArray.ml
<kaustuv> thelema: I think a batteries-lite flavour would be good to have in addition to the full distribution, for those who are highly suspicious of camlp4 (and like to use $ and << in their own code)...
<eyda|mon> thelema: I've already installed godi. Can I use it now by using open extArray or something?
<thelema> I might be able to argue successfully for two-tiers of batteries, but our intent has been to standardize this kind of thing, and tiers of functionality defeats that purpose.
<kaustuv> but you already have threaded and non-threaded tiers!
<kaustuv> well, not tiers but alternatives
<thelema> eyda|mon: oh, working within godi, you should be able to do some sort of "godi install batteries" - sorry, I don't use godi
<thelema> threaded/non-threaded is pretty unavoidable, unless we wanted to insist that everyone use the threaded runtime to use batteries.
<thelema> hmm, maybe I was on the wrong side of that argument...
Cromulent has quit []
bacam has quit [Read error: 113 (No route to host)]
* brendan is highly suspicious of camlp4 :)
* thelema doesn't use it himself, but mostly because it's not integrated into the normal compilation process
<brendan> well, not really. It's just it mostly comes up when a colleague insists on writing things in revised syntax
* thelema doesn't find the revised syntax worth the compilation hassles.
<brendan> no, me neither
<thelema> although if it were integrated into the source, so that the regular compiler could notice a [pragma syntax=revised] directive or something, that would *much* lower the hassle (and maybe some confusion)
<brendan> I got the impression it was dying out anyway
<thelema> It's not used, I think mostly because it's a pain to use.
<thelema> maybe "batteries-lite" = "battery"
<thelema> or maybe that's just confusing.
<eyda|mon> ugh. now I look... port install caml-batteries was all I needed.
<eyda|mon> godi seems very very new and wasn 't very user friendly
<eyda|mon> i can see why you don't use it
<thelema> godi is quite old, iirc.
<brendan> AAA batteries?
<thelema> like that.
<thelema> godi's mailing list archive goes back to 2004
eyda|mon has quit [Remote closed the connection]
eyda|mon has joined #ocaml
<kaustuv> GODI is nowhere near as friendly as apt-get install, but sometimes it's the only option.
<kaustuv> The real problem is though that the OCaml user experience is still very painful, despite findlib, ocamlbuild, etc. In an ideal world we'd have a ocaml equivalent of ghc --make that would Just Work(tm)
<Spiwack> In an ideal world we could configure apt-get to install from svn.
<Spiwack> Though of course, all the unpackaged libs would suffer.
<Spiwack> Mmm
* thelema just wants camlp4 that can include other camlp4 macors
<thelema> *processors
<thelema> brb
thelema has quit ["leaving"]
eyda|mon has quit [Remote closed the connection]
eyda|mon has joined #ocaml
bombshelter13__ has joined #ocaml
bombshelter13__ has quit [Remote closed the connection]
bombshelter13__ has joined #ocaml
thelema has joined #ocaml
bombshelter13_ has quit [Connection timed out]
sramsay has joined #ocaml
ofaurax has joined #ocaml
eyda|mon has quit [Remote closed the connection]
eyda|mon has joined #ocaml
slash_ has joined #ocaml
^authentic has joined #ocaml
Spiwack has quit ["Leaving"]
authentic has quit [Read error: 110 (Connection timed out)]
Snark has quit [Read error: 113 (No route to host)]
BiDOrD has joined #ocaml
damg has joined #ocaml
ulfdoz has joined #ocaml
eyda|mon has quit [Remote closed the connection]
eyda|mon has joined #ocaml
eyda|mon has quit [Remote closed the connection]
eyda|mon has joined #ocaml
Anarchos has quit ["Vision[0.9.7-H-090423]: i've been blurred!"]
<eyda|mon> If I have stuff.ml as a module, is there anyway I can call Stuff.func(); from another ml as an Ocaml script? How?
<eyda|mon> seems I can do ocamlopt -c stuff.ml .. ocamlopt -o blah stuff.cmx
<eyda|mon> but what if I want to run interpreted?
damg has quit [Read error: 110 (Connection timed out)]
_andre has quit ["leaving"]
julm has joined #ocaml
bombshelter13__ has quit [Client Quit]
ulfdoz has quit [Read error: 110 (Connection timed out)]
eyda|mon has quit [Read error: 110 (Connection timed out)]
ofaurax has quit ["Leaving"]
erickt has quit ["Leaving."]
erickt has joined #ocaml
sramsay has quit [Remote closed the connection]
julm_ has joined #ocaml
julm has quit [Read error: 113 (No route to host)]
julm_ is now known as julm
hkBst has quit [Read error: 104 (Connection reset by peer)]
thelema_ has joined #ocaml