mfp changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | OCaml 3.11.2 released | Inscription for OCaml Meeting 2010 is opened http://wiki.cocan.org/events/europe/ocamlmeetingparis2010
ccasin has joined #ocaml
oriba_ has joined #ocaml
oriba has quit [Ping timeout: 248 seconds]
pimmhogeling has joined #ocaml
sepp2k has quit [Quit: Leaving.]
bzzbzz has joined #ocaml
oriba_ has quit [Quit: Verlassend]
enthymeme has quit [Quit: rcirc on GNU Emacs 23.1.1]
_unK has quit [Remote host closed the connection]
pimmhogeling has quit [Ping timeout: 265 seconds]
joewilliams_away is now known as joewilliams
joewilliams is now known as joewilliams_away
ccasin has quit [Quit: Leaving]
Shoggoth has joined #ocaml
ygrek has joined #ocaml
jakedouglas has quit [Quit: Leaving.]
ygrek has quit [Ping timeout: 245 seconds]
Shoggoth has quit [Remote host closed the connection]
ygrek has joined #ocaml
MrEvil has joined #ocaml
ftrvxmtrx has quit [Ping timeout: 240 seconds]
ftrvxmtrx has joined #ocaml
MrEvil has quit [Quit: This computer has gone to sleep]
Submarine has joined #ocaml
ygrek has quit [Ping timeout: 245 seconds]
julm has quit [Quit: free at last]
julm has joined #ocaml
julm has quit [Quit: rah]
julm has joined #ocaml
ygrek has joined #ocaml
Chicco has joined #ocaml
hyperbor1ean has quit [Quit: leaving]
hyperboreean has joined #ocaml
leino has joined #ocaml
oriba has joined #ocaml
pimmhogeling has joined #ocaml
pimmhogeling has quit [Ping timeout: 265 seconds]
Asmadeus has quit [Disconnected by services]
Asmadeus_ is now known as Asmadeus
sepp2k has joined #ocaml
Chicco has quit [Ping timeout: 245 seconds]
Chicco has joined #ocaml
Yoric has joined #ocaml
spearalot has joined #ocaml
orbitz_ has joined #ocaml
leino has quit [Quit: leaving]
leino has joined #ocaml
orbitz has quit [Ping timeout: 252 seconds]
orbitz_ has quit [Quit: Reconnecting]
orbitz has joined #ocaml
fraggle_ has quit [Ping timeout: 260 seconds]
fraggle_ has joined #ocaml
Associat0r has quit [Read error: Connection reset by peer]
spearalot has quit [Quit: Computer has gone to sleep]
derdon has joined #ocaml
spearalot has joined #ocaml
_unK has joined #ocaml
spearalot has quit [Quit: Computer has gone to sleep]
spearalot has joined #ocaml
ygrek has quit [Remote host closed the connection]
fraggle_ has quit [Ping timeout: 268 seconds]
fraggle_ has joined #ocaml
ygrek has joined #ocaml
soupdragon has joined #ocaml
sdschulze has joined #ocaml
<sdschulze> Hi everyone... I've been using OCaml for about a month now, and I've collected some questions in mind...
<sdschulze> First, say I have a class that contains a variable that has a type that includes the class itself (as a variant, a record list, whatever).
soupdragon has left #ocaml []
<sdschulze> How can I make such a mutually recursive definition between a class and a type?
<derdon> sdschulze: paste some code, please
<derdon> avoids misunderstandings
<sdschulze> ok, just a minute...
Yoric has quit [Ping timeout: 259 seconds]
<derdon> afk, eating
Yoric has joined #ocaml
<sdschulze> That's actually what I was trying to do.
<sdschulze> A workaround for this specific problem might a using PSet from batteries, but you can easily construct similar scenarios.
<flux> recursive modules would solve this sort of problem in a generic fashion
<sdschulze> flux: "would"? Are they supported?
<flux> yes
<flux> but they are slightly annotation-heavy..
<flux> but there are other ways, such as using polymorphic types but I'm not sure if it works here
<flux> actually I think in this case recursive modules is the only way to go
Chicco has quit [Ping timeout: 240 seconds]
<sdschulze> Another, more constructed scenario looks like this: type parent_option = Parent of node | NoParent
<sdschulze> I fail to come up with a realistic example right now...
<flux> actually for this particular case it isn't that heavy syntactically: http://www.modeemi.fi/~flux/software/ocaml/mutrec.ml
<derdon> re
Chicco has joined #ocaml
<sdschulze> flux: OK, thanks
<flux> sdschulze, an alternative would be to have the whole module be recursive. that would allow direct access to all the functions in Node_set, which might be what you're after..
<flux> sdschulze, of course, if you just stick in the 'interface' class, you can cast your actual object into that
<flux> (infact it might not even need casting)
spearalot has quit [Quit: -arividerchi]
<sdschulze> Another general question about sets: what data type is used for their internal representation and why are manipulations on them purely functional?
<flux> for sets?
<flux> ah, yes :)
<flux> they are red-black binary trees
<flux> and they are functional, because that's how we roll in functional languages..
<flux> if you want 'mutable', you can make-do with a reference type
<flux> if mutable was the default, there would be no going back to immutable
<sdschulze> Doesn't adding an element involve reordering of the tree?
<flux> it might, but you can usually use a great part of the original tree as-is
<flux> and the new tree is mostly shared with the old one
<flux> what really is new is the path to the newly inserted nodes, and some other nodes if rebalancing is required
<flux> in red-black trees the r/l branch can be at most 2x the depth as the opposite branch, so it is not rebalanced continuously
<flux> s/continuously/repeatedly/
<sdschulze> ok
<flux> actually it turns out I misremembered, they are not red-black-trees. looks like avl trees, not sure.
<flux> btw, map.ml is only 200 lines (and doesn't depend on anything), so it's feasible to read ;)
<sdschulze> I already found it before, but my knowledge on trees isn't that good, so I didn't recognize it at once.
<sdschulze> Is immutability better for the compiler?
<sdschulze> (can it maybe store the payload unboxed?)
<det> Yeah, ocaml set/map is avl tree
<flux> well, the compiler might be geared towards immutability, but afaik one big winner is the garbage collector, which like immutability
<flux> which likes, even
<thelema> flux: avl trees w/ height distance at most 2
<flux> thelema, I guess that assertion changed in the RB/AVL mixup :)
<det> I think immutability is over rated
<thelema> det: immutability is nice when it's nice and inconvenient when it's inconvenient. Having few immutable values in a program makes it easier to reason about
<det> I think immutability often makes the program convoluted
<flux> det, well, as I said: it's much easier to go from immutable to mutable than the reverse
<det> Sometimes a "for" loop + mutation is much easier to understand than a fold
<sdschulze> flux: Why exactly? If you consider the easier example of immutable lists, you cannot change the tail of a list, but you can still refer to it, so the respective object must be known to the GC.
<flux> I must admit I have sometimes written some quite convoluted folds..
<det> me too
ccasin has joined #ocaml
<thelema> Many folds are just while loops in disguise, true
<det> very tempting to convert to iter/mutation
<derdon> fold, map etc. are simply cool 8)
<derdon> for and while are not cool at all
<det> well
<flux> sdschulze, I don't know the details, that's just the general concensus I've seen from mailing lists. apparently immutability is somehow exploited by the gc.
<det> foreach is really just iter
<flux> what det probably means are situations when you usually use fold
<derdon> det: and the difference is again: coolness
<derdon> det: foreach is not cool, but iter is
<flux> for example if you need to fold over a structure that has static three levels and keep summing some values
<flux> well, obviosuly you can do it as I've done it quite a few times
<sdschulze> flux: OK, it might give you a factor of two.
<flux> but I cannot help thinking that simply putting three foreach-inside-foreach updating a mutable variable would be simpler
<det> yeah, that is a good example
<sdschulze> As the tutorial says: loops are second-class citizens in OCaml.
<det> i never have the urge to use while or for in Ocaml
<flux> sdschulze, btw, I put up a new mutrec.ml, it demonstrates the fully recursive module -based solution
<sdschulze> flux: OK, thanks
<sdschulze> det: It's probably about as cool as trying to do a fold in C...
<flux> there are counter-examples to mutation though. for example I hate the interface of the Arg-module, as it requires using mutability ;)
<det> I've never used the Arg module
<det> I agree though, I'd like both options available
<flux> my fold-based (simple) version allows separating the argument list fully separate from the variables themselves
<flux> but there is a price to pay..
<flux> (["--port"; "-p"], CmdArg.int (fun c port -> { c with c_port = port }),
<flux> ("port", "Set the port to listen (default: " ^ string_of_int default.c_port ^ ")"));
<det> ya, I cant help but think mutating a record would be simpler than function record update
<det> btw
<det> why not use Printf
<flux> I usually do, infact..
<flux> but it looked more similar to other strings that simply concatenated other strings
<det> printf is always easier for me to read
<sdschulze> The general problem I see about using things like lists is that the number of GC objects is linear to the length of the list.
<flux> obviously it's not if you never modify the end?-)
<sdschulze> ?
Yoric has quit [Ping timeout: 276 seconds]
mal`` has quit [Quit: Coyote finally caught me]
<flux> I was actually thinking a simplified case. for example for a list of ints the gc could know that if all its elements are already moved into the long-term gc pool, it doesn't need to scan it ever again?
<flux> not convinced that gc would do that kind of analysis though :)
mal`` has joined #ocaml
<sdschulze> Dunno, is it generational?
<flux> yes
<sdschulze> Hm, currently reading: http://pauillac.inria.fr/ocaml//numerical.html
<sdschulze> So polymorphism is rather bad for unboxing?
<flux> yes, unless you throw out the uniform data representation
<sdschulze> Are there any papers that describe the way OCaml works internally?
<mfp> sdschulze: if you're interested in the data representation and some GC details, the "Interfacing C with OCaml" part of the manual might help you
sdschulz` has joined #ocaml
sdschulze has quit [Read error: Operation timed out]
<mfp> sdschulz`: <mfp> sdschulze: if you're interested in the data representation and some GC details, the "Interfacing C with OCaml" part of the manual might help you
sdschulz` has left #ocaml []
sdschulze has joined #ocaml
<sdschulze> mfp: thanks
<derdon> which ocaml lib can be recommended for parsing command line options? it should respect the POSIX standard, i.e. accept short and long options for example (the Arg module from the stdlib falls therefore out)
<flux> derdon, I haven't tried, but atleast ocaml-getopt promises that in its name..
<derdon> flux: good. thank you!
<derdon> many ocaml projects lack of good documentation
<derdon> or of documentation in general
<flux> mli-files go a long way
<derdon> flux: mhh
<derdon> flux: online or pdf files are much better to read
ikaros has joined #ocaml
<sdschulze> .mli files don't include the variable names for the function arguments, so they suck for documentation.
<flux> it is rare you see functions like val frabilucate : int -> int -> int -> int -> int
<flux> so value and type names and library's purpose both need to be taken into account :)
<flux> of course, if you're lucky, there is a comment with parameter names at the value declaration site
<flux> and if you're really lucky, there's some actual genuine well-written documentation on how to use the library, with examples!
<derdon> flux: and this is what I expect!
<derdon> this is what I am used to from other programming languages (python)
<derdon> see the pocoo projects on dev.pocoo.org
<derdon> they have great documentation
<flux> perhaps there's less social pressure or something to make ocaml writers write documentation
<flux> or perhaps they are not immersed in examples of other people doing that
<derdon> so we'll start with good documentation to impress other ocaml programmers and make them imitate us :D
leino has quit [Quit: Lost terminal]
jimi_hendrix has joined #ocaml
<jimi_hendrix> hello
<jimi_hendrix> where would the best starting place to learn ocaml be?
<derdon> jimi_hendrix: the official tutorial, ocaml-tutorial.org, and the o'reilly book
<derdon> no particular order here; I read from everything every day a bit ;)
<jimi_hendrix> i see
<jimi_hendrix> and what would be a good simple project to make to test my knowledge?
<jimi_hendrix> i have not used a functional language before
<derdon> jimi_hendrix: hm. the typical excercise is "guess a number"
<derdon> these excercises don't have to be related to functional programming, btw
<derdon> you can try to write an addressbook
<derdon> I love lexing & parsing, so I wanted to start with ocamllex and ocamlyacc very early
<derdon> a few days ago, I started with an invented esoteric programming language :D
<jimi_hendrix> ah
<derdon> jimi_hendrix: and it's very important to learn a lib which extends the standard lib of ocaml, e.g. the batteries
<jimi_hendrix> why is that?
<derdon> jimi_hendrix: because the stdlib of ocaml is rather small
<derdon> and it doesn't offer nice functions for I/O, for example
<derdon> I don't know how the batteries work with unicode, but I know that the standard lib of ocaml is bad at it
<jimi_hendrix> i see
<jimi_hendrix> what lib would you recommend?
<derdon> jimi_hendrix: surprise, surprise: the batteries :D
joewilliams_away is now known as joewilliams
jakedouglas has joined #ocaml
ulfdoz has joined #ocaml
joewilliams is now known as joewilliams_away
Chicco has quit [Ping timeout: 246 seconds]
<thelema> 11:00 < det> i never have the urge to use while or for in Ocaml
<thelema> det: the algorithm that most encouraged for loops in my ocaml was:
pimmhogeling has joined #ocaml
<thelema> All pairs shortest path -- with three nested for loops
<thelema> which I can't seem to find at the moment...
<thelema> But here's the pseudocode from wikipedia: http://en.wikipedia.org/wiki/Floyd-Warshall_algorithm#Pseudocode
oriba has quit [Remote host closed the connection]
<thelema> aha, found my ocaml implementation: http://pastebin.com/srfpdvTh
marchdown has joined #ocaml
<flux> wayy too succinct. you should've used maps from integer tuples to integers and lazy evaluation!
<sdschulze> enums?
<sdschulze> flux: Do you have pointers to mutable vs. immutable discussions on the mailing list?
<flux> sdschulze, I don't recall
<flux> could be
<flux> (that such discussions exist)
<thelema> flux: lol
<thelema> It's a solidly imperative algorithm from the start, and there's little need to mess it up with wild high-level re-engineering
<det> rewriting that to use recursion would probably be a PITA
<sdschulze> BTW, is there any good reason why doubly-linked lists in Batteries can't be empty?
<det> thelema, I think this is probably equivalent
<det> and if range was a standard library function, just as short
Chicco has joined #ocaml
ttamttam has joined #ocaml
<flux> sdschulze, I haven't used it, but possibly it is intended to be used as a low-level building block for other data structures
<flux> (it seems to have quite low-level operations)
<flux> ..although that would seem to be too specialized module for Batteries..
<flux> why not provide the Knot node or something?
<flux> you can implement it yourself, of course, at the cost of some space
<sdschulze> maybe polymorphism problems?
<flux> doesn't seem likely
<flux> (infact, highly unlikely)
leino has joined #ocaml
sepp2k has quit [Quit: Leaving.]
pimmhogeling has quit [Ping timeout: 265 seconds]
pimmhogeling has joined #ocaml
Jedai has joined #ocaml
boscop_ has joined #ocaml
boscop has quit [Ping timeout: 248 seconds]
Chicco has quit [Ping timeout: 260 seconds]
jonafan_ has joined #ocaml
jonafan has quit [Ping timeout: 240 seconds]
pimmhogeling has quit [Remote host closed the connection]
M| has quit [Ping timeout: 258 seconds]
M| has joined #ocaml
Chicco has joined #ocaml
sepp2k has joined #ocaml
<thelema> sdschulze: just am implementation detail. If you want an emptiable double-linked-list, use Dllist.t option
<thelema> det: it seems your version is less readable
<thelema> and wrong, btw
<det> wrong ?
<thelema> it's important the order of kij in the loops
<det> oops
<det> easy fix
<det> I wouldnt write it the way I did
<det> because ocamlopt isnt able to turn that into efficient loops
<det> but Im just saying that I dont care much about special forms like while/for
<thelema> and I'm just saying that there's a reason they exist, and they're quite handy for the things they're designed for.
marchdown has quit [Quit: marchdown]
marchdown has joined #ocaml
Submarine has quit [Quit: Leaving]
pad has joined #ocaml
marchdown has quit [Quit: marchdown]
ulfdoz has quit [Read error: Operation timed out]
Chicco has quit [Ping timeout: 252 seconds]
enthymeme has joined #ocaml
marchdown has joined #ocaml
ygrek has quit [Ping timeout: 245 seconds]
oriba has joined #ocaml
marchdown has quit [Quit: marchdown]
sepp2k1 has joined #ocaml
sepp2k has quit [Ping timeout: 264 seconds]
marchdown has joined #ocaml
eb4890 has joined #ocaml
derdon has quit [Ping timeout: 245 seconds]
* adrien watches the mailing-list and wonders how long it can last
ikaros has quit [Quit: Leave the magic to Houdini]
ttamttam has quit [Quit: Leaving.]
boscop_ has quit []
sepp2k1 has quit [Quit: Leaving.]
oriba has quit [Quit: Verlassend]
Amorphous has quit [Ping timeout: 265 seconds]
Amorphous has joined #ocaml