hcarty 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
rcloud has joined #ocaml
rcloud has quit [Remote closed the connection]
rcloud has joined #ocaml
rcloud has quit [Remote closed the connection]
rcloud has joined #ocaml
rcloud has quit [Remote closed the connection]
travisbrady has quit ["Computer has gone to sleep"]
slash_ has quit [Client Quit]
rcloud has joined #ocaml
rcloud has quit [Remote closed the connection]
rcloud has joined #ocaml
rcloud has quit [Remote closed the connection]
rcloud has joined #ocaml
tmaeda0 has joined #ocaml
tmaeda has quit [Read error: 110 (Connection timed out)]
jeddhaberstro has quit [Client Quit]
rcloud has quit [Remote closed the connection]
rcloud has joined #ocaml
rcloud has quit [Remote closed the connection]
rcloud has joined #ocaml
rcloud has quit [Remote closed the connection]
thrasibule has quit [Read error: 110 (Connection timed out)]
travisbrady has joined #ocaml
lanaer_ has joined #ocaml
lanaer has quit [Read error: 110 (Connection timed out)]
caligula__ has joined #ocaml
caligula_ has quit [Read error: 110 (Connection timed out)]
Alpounet has joined #ocaml
Ched has joined #ocaml
f[x] has joined #ocaml
travisbrady has quit ["Computer has gone to sleep"]
ttamttam has joined #ocaml
ztfw has quit [Remote closed the connection]
ztfw has joined #ocaml
f[x] has quit [Read error: 110 (Connection timed out)]
_zack has joined #ocaml
verte has joined #ocaml
f[x] has joined #ocaml
rwmjones_afk is now known as rwmjones
dmentre has joined #ocaml
hkBst has joined #ocaml
th5 has joined #ocaml
Associat0r has joined #ocaml
espresso has joined #ocaml
f[x] has quit [Read error: 110 (Connection timed out)]
yurug has joined #ocaml
julm has quit ["banzaï !"]
th5 has quit [Remote closed the connection]
th5 has joined #ocaml
julm has joined #ocaml
Guest1908 is now known as fremo
olegfink has quit [Remote closed the connection]
julm has quit ["bye"]
julm has joined #ocaml
tmaeda0 has quit [Read error: 60 (Operation timed out)]
tmaeda has joined #ocaml
julm has quit ["fuck !"]
rwmjones_ has joined #ocaml
rwmjones has quit [Read error: 104 (Connection reset by peer)]
julm has joined #ocaml
komar_ has quit [Read error: 110 (Connection timed out)]
_andre has joined #ocaml
f[x] has joined #ocaml
Snark has joined #ocaml
_zack has quit ["Leaving."]
julm_ has joined #ocaml
julm has quit [Nick collision from services.]
julm_ is now known as julm
albacker has joined #ocaml
komar_ has joined #ocaml
Ched has quit [Read error: 101 (Network is unreachable)]
Associat0r has quit []
komar_ has quit ["WeeChat 0.2.6.3-ohshi"]
komar_ has joined #ocaml
rwmjones_ is now known as rwmjones
willb has joined #ocaml
Jedai has joined #ocaml
Jedai has quit [Remote closed the connection]
Jedai has joined #ocaml
Jedai has quit [Client Quit]
ttamttam has quit ["Leaving."]
verte has quit ["~~~ Crash in JIT!"]
_zack has joined #ocaml
blackdog has left #ocaml []
bzzbzz has joined #ocaml
Ched has joined #ocaml
Jedai has joined #ocaml
Amorphous has quit [Read error: 110 (Connection timed out)]
Amorphous has joined #ocaml
Ched has quit ["Ex-Chat"]
ttamttam has joined #ocaml
espresso has quit [Read error: 104 (Connection reset by peer)]
espresso has joined #ocaml
slash_ has joined #ocaml
dmentre has quit ["Leaving."]
hkBst has quit [Read error: 104 (Connection reset by peer)]
petchema has joined #ocaml
<thelema> lazyIRC: I'm trying to find the story of a problem given to a team of programmers who make a complex solution using all their available time, and also a single programmer who thinks about it for a while, and comes up with a simple solution.
<thelema> The story ends with the team of programmers impressing their boss with lots of complex code and getting a raise, and the single programmer not getting fired for all the "goofing off" he did while thinking.
<gildor_> thelema: it is all about java
<gildor_> vs people who don't do UML
* thelema thought it was about the disincentives of doing a good job
<thelema> but yes, there was some modeling by the complex team
caligula_ has joined #ocaml
travisbrady has joined #ocaml
smimou has joined #ocaml
caligula__ has quit [Read error: 110 (Connection timed out)]
ulfdoz has joined #ocaml
BigJ has joined #ocaml
willb has quit [Read error: 110 (Connection timed out)]
lanaer_ is now known as lanaer
ttamttam has quit ["Leaving."]
travisbr1dy has joined #ocaml
Associat0r has joined #ocaml
Associat0r has quit [Client Quit]
travisbrady has quit [Read error: 110 (Connection timed out)]
willb has joined #ocaml
_zack has quit ["Leaving."]
<albacker> there's not a method of List to get the n-th element of the list ?
<albacker> in the library i can't see one in fact.
<Camarade_Tux> List.nth (even though it's bad practice ;) )
<albacker> bad practice? Why ??
<Camarade_Tux> well, it's not bad practive per se but it's pretty slow and usually you can do what you want much faster
* Camarade_Tux in a hurry right now
<albacker> thnx
Jeff_123 has joined #ocaml
Jeff_123 has quit [Client Quit]
Jeff_123 has joined #ocaml
f[x] has quit ["Leaving"]
f[x] has joined #ocaml
Jeff_123 has quit [Client Quit]
ttamttam has joined #ocaml
<det> albacker, if you are doing a lot of random access on a list you are better off coverting it to an array
komar__ has joined #ocaml
<albacker> thanks deavid
<albacker> det *
<det> albacker, if you are iterating over all elements, then you are better off using List.fold_left, or a loop that deconstructs it
<det> albacker, what are you doing with the list ?
<det> an Ocaml list is not like a Python list, to get the nth element, it has to iterate over n elements
<flux> which includes operations like List.length
<flux> actually when I begun learning ocaml, it was unclear to me what would be the complexity of it. of course, now that I know that the recursive definition of the type is all there is, I can know the answer
<det> append is another operation that is bad on lists
<albacker> det, i wanted to get the 2nd element always in a recursive function
<det> you can use pattern matching for that
<albacker> i havent started using it yet :(
<albacker> its been 4-5 days im learning ocaml
<det> # let f l =
<det> match l with
<det> _ :: element :: _ -> element
<det> | _ -> failwith "invalid list"
<det> ;;
<det> val f : 'a list -> 'a = <fun>
<det> # f [];;
<det> Exception: Failure "invalid list".
<det> # f [1];;
<det> Exception: Failure "invalid list".
<det> # f [1; 2];;
<det> - : int = 2
<det> # f [1; 2; 3];;
<det> - : int = 2
<hcarty> albacker: Starting out with OCaml, using List.nth to get the second element in the list is not such a bad thing. But you may want to look in to either using an array or pattern matching (like det just pasted).
<albacker> hcarty, det thanks for the help :)
<det> pattern matching may or may not be best here
<hcarty> albacker: I still have code floating around which uses List.nth because I haven't had a need to change it. As you will likely learn, though, it can make code more fragile.
<det> depends on your other cases
<det> with pattern matching, it is easy to make special cases for the empty list or list of 1 element
<det> I've never felt the need to use List.nth
<albacker> inmy case pattern matching is better though i'm just looking.. with it i can have less lines compared to all the if-s i'd have to write.
<det> if you are going to handle the expcetion that List.nth can raise, then pattern matching is easier
<det> and clearer
<det> exception*
komar_ has quit [Read error: 113 (No route to host)]
<hcarty> det: Coming from a background of non-listy languages, List.nth can seem like the natural solution when you want the nth element of a list. Until the code grows, the exceptions start flying, and everything just gets ugly :-)
<det> "list" in a lot of other languages is a more general datastructure
<hcarty> At which point the applicability of pattern matching starts to become more apparent, along with the benefits of OCaml's safer/better checked approaches to code.
<hcarty> det: Yes, the relatively rigid definition of a list in OCaml when compared with the relaxed definition in Perl or Python takes a bit of adjustment.
<det> I think list is overemphasized in functional languages
<flux> det, how do you mean?
<det> for example
<flux> it is the basic functional data structure
<det> it is common to accumulate to list and then reverse
<flux> except in haskell..
<flux> linear typing could enable not doing that and still be safe
<flux> (and strict)
<det> I think it would be better to use a datastructure with an interface and properties that suit your needs better
<det> even if that datstructure is just using a list internally with prepend/reverse
<flux> would such a datastructure be functional?
<det> sure
<flux> or its interface
<det> sure
<flux> so which data structure were you thinking of?
<det> something like this
<det> although push should probably be called append
<flux> the site's not responding to me :/
<flux> cool, it has ipv6!
<flux> ..too bad it's not working
<flux> so you're thinking of the functional queue
<flux> which indeed cannot avoid the reverse step, but you didn't require it anyway
<det> right
<det> but it is more about the interface
<det> more clear and flexible
<flux> I suppose people could easily use queue too, and just finally extract the list result. or perhaps not extract it at all, leave it as is.
<det> just define fold/etc in there
<flux> the thing is that lists are also first-class citizens in ocaml in terms of for example pattern matching
<flux> I wonder if batteries has that
<flux> if not, it should be submitted :) (I'm not even sure if extlib has it.. it has dllist, but that's imperative)
<det> Yeah, pattern matching on an interface is an interesting problem
<flux> views is one possible solution to that
<flux> and there are some camlp4-based attempts to provide such facilities
<det> Seems like lazy evaluation maybe solves that
<det> just convert to list ?
<flux> before pattern matching?
<det> yeah
<flux> that could turn out to be veeery slow, if you keep doing operations on it afterwards
<flux> let's say you extract the first element of a queue
<flux> and then recurse to the rest of the queue
<flux> well, maybe that could be decent speed
<det> that corresponds to a pop
<flux> but let's say your data structure was a binary tree
<flux> ..or a file..
<det> I dont see the problem
<det> I guess what I would like is to keep all type abstract, but have constructors that arent real, but form an interface, if that makes sense
<flux> let rec iter f t = match BinaryTree.to_list t with [] -> () | smallest_element::tree_without_smallest_element -> f smallest_element; iter f (BinaryTree.of_list tree_without_smallest_element)
<det> that would be a silly way to write that, though
<det> define the loop on lists and coerce before passing to the loop
<det> Well
<det> I guess you dont always want to go to list and never come back
ulfdoz has quit [Read error: 110 (Connection timed out)]
<det> btw, am I the only person who hates of_XX named functions?
<flux> yes
<det> to_X, from_X is so much clearer to me
<flux> it's a great naming convention :)
<flux> well, that's an alternative, but 'of' is already the convention, so you lose :)
<det> I always have to stop and think what i means though
<flux> (in the end, it doesn't matter, and of_ is shorter)
<det> I've never seen of_X used outside caml though
<det> so in the bigger picture... :-)
<det> List.fromArray in SML, for example
<det> another thing about lists is that people often use them when arrays would be better
<hcarty> That automatically loses because it's camelCase, so it's automatically wrong :-)
<det> yeah, I prefer _ myself
<det> I think a problem is that is hard to write generic code in Ocaml
<hcarty> det: Generic in what way?
<det> such as a function that operates on any type of sequence
<det> you can functor the whole module, but that is often too.. whats the opposite of fine grained?
<flux> coarse grained
<det> yes that
<flux> it's not that difficult to functorize a module, though
<det> or you can pass functions, but that can get really awkward and break code a lot
<det> that is why I like type classes, fine grained
<det> I wonder how practical multiple paramater type classes applied to sequences would be
<det> so you could write a function like:
<det> let sum seq = Seq.fold_left Num.add Num.zero seq
<det> that would operate any any kind of sequence of any kind of number
<det> I wonder if type inference would often break down
<hcarty> det: How does passing functions break code a lot?
<flux> here's something related from channel /lastlog: let pow = generic_pow ~zero ~one ~div_two:(fun n -> n / 2) ~mod_two:(fun n -> n mod 2) ~mul
<hcarty> I agree it can be awkward.
<det> you need a parameter for every operation
<det> and the required operations may change
<det> and you dont have first class modules
<flux> objects \o/
<flux> although indeed first class modules could be nice
<det> objects are a bit diff
<flux> too bad the patches never went in to the official tree
<flux> the problem with objects for this purpose would be that they'd need special annotation
albacker has quit ["Leaving"]
<flux> (well, not special, just ordinary type annotations)
<det> objects lock your data up in an existential jail
<flux> I don't remember if the first class module -patch required it
<flux> det, I mean a module like: class list = object method fold_left : 'a.'b. ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a end
<flux> or maybe 'b list is a bad type there :)
<flux> but classes cannot have types, which is what first class modules would bring..
<flux> (you could pass modules made with functors to functions)
<flux> actually I wonder if one could provide such a set of useful classes or not
<det> I dont think you could write my sum example using objects
f[x] has quit [Read error: 110 (Connection timed out)]
Snark has quit ["Ex-Chat"]
Demitar has quit ["Ex-Chat"]
ttamttam has quit ["Leaving."]
bzzbzz has quit ["Lost terminal"]
_andre has quit ["leaving"]
espresso has quit [Read error: 104 (Connection reset by peer)]
espresso has joined #ocaml
espresso has quit ["Leaving"]
Associat0r has joined #ocaml
th5 has quit [Read error: 110 (Connection timed out)]
thrasibule has joined #ocaml
<Camarade_Tux> anyone know how to generate the .mli files when using OCamlMakefile? (actually the question should be: is it possible?)
<Alpounet> ocamlc -i
<Alpounet> thus, just add -i to the options
<orbitz> I still haven't fully come to grok modules/signatures/structs in ML
<Alpounet> there are actually powerful... the parametrized modules system (aka module functors) is powerful.
<orbitz> The only place I have actually use dthem is Map/Set
<orbitz> and i found them to be a PITA
<Camarade_Tux> Alpounet: I can't just drop -i in in OCamlMakefile unfortunately
<Alpounet> Camarade_Tux, why ?
<Camarade_Tux> at least I don't see where I should (I have several .ml files and it's doing almost everything automatically)
<orbitz> anyone else suitably unimpressed with Noop?
<Alpounet> However, the thing that I enjoy the most in OCaml is the structural polymorphism, mostly over objects.
<Alpounet> (you have it with module functors too)
<orbitz> Alpounet: could yo be more concrete?
<Camarade_Tux> Asmadeus: I don't use ocamlbuild at all for that since I'm linking against C libraries (no, I haven't tried the project that should add that to ocamlbuild, ocamlmakefile works too well)
<Asmadeus> ah. my bad, misread
<Camarade_Tux> Santa will bring you a shiny new pair of eyes :p
<orbitz> and gouge out the bad ones!
travisbr1dy is now known as travisbrady
<Asmadeus> my eyes ought to be fine, I read a 5x7 font on a 1280x800, 15" display
<Camarade_Tux> I had to stop at 6pt because antialiasing made all letters similar at 5pt ='(
<Alpounet> orbitz, structural as opposed to nominal
<Alpounet> in Haskell with typeclasses, in OO languages with type hierarchies, we use polymorphism attached to a noun (the base class' type in OO languages, the typeclass' name in Haskell) to refer to some interface shared by all the "subtypes" (OO) or "instances" (Haskell)
<Camarade_Tux> ok, ocamlmakefile currently can't create the .mli by itself (that's what I guess since it doesn't have the string '-i ' anywhere)
<Alpounet> in OCaml with objets and module functors, in C++ with templates, the polymorphism comes from a minimal structure we ask our type to have, like in :
<Alpounet> template <class T> void foo(T& t) { t.this_is_a_great_function(); }
<Alpounet> here, to call foo with T being some type, we need <some type> to have *at least* a function called "this_is_a_great_function"
<Alpounet> it can have 121039383984 other member functions (even if that's not a good sign and I wouldn't be the one who would maintain the code after this guy), we don't care
* Camarade_Tux decided to skip installing the .mli for now...
<Alpounet> we just put one constraint on T, having a this_is_a_great_function member function fitting the way we call it (it can have an argument with a default value, etc)
<Alpounet> it's polyrmorphic, because many types (an infinity, if we want) can satisfy this constraint
<Alpounet> but it's only based on the structure of our type
<Alpounet> we have the same thing in OCaml
<Alpounet> let foo my_object = myobject#foo "Yeah";;
<hcarty> Camarade_Tux: I have some myocamlbuild.ml magic for working with C stubs and camlidl if you have any interest. Sticking with OCamlMakefile is probably easier though since it seems to be much better at Just Working.
<Alpounet> here we just ask my_object to have a member function called foo taking a string as argument
<Alpounet> (it can have default values etc, same as with C++)
willb has quit [Read error: 110 (Connection timed out)]
<Alpounet> orbitz, you see ?
<Camarade_Tux> hcarty: ocamlmakefile definitely works well but I'd like to test what you have (not today though, it's getting a bit late ;) )
<Associat0r> subtype polymorphism
<Alpounet> Associat0r, still, this isn't structural
<Alpounet> the only structural polymorphism related stuffs in Haskell are in Template Haskell / Generic Haskell
<Alpounet> Mostly GH.
<Associat0r> Alpounet true
<Alpounet> Associat0r, but I'm not saying the dynamic dispatch simulation isn't good. Actually, that's very smart, and has made me do some interesting progress in the understanding of Haskell.
<hcarty> Camarade_Tux: Ok, let me know when you have both the interest and the time :-)
<orbitz> Alpounet: sorry stepd away, reading
<Alpounet> orbitz, okay.
<Camarade_Tux> hcarty: sure, I just need to find a way to torture gobject-introspection developpers for being that useless :)
<Camarade_Tux> first
<Associat0r> Alpounet thanks for the paper btw
<orbitz> Alpounet: you can't accomplisht hat with typeclasses?
<Camarade_Tux> good night
willb has joined #ocaml
<Alpounet> orbitz, nope
<Alpounet> when you have : f :: (Show a) => a -> b
<Alpounet> in Haskell
<orbitz> oh i see what you mean
<Alpounet> it is nominal
<orbitz> i have never heard that word in this context
<Alpounet> In Java, you'd have written it this way : b f(Showable x) { }, with being the interface with the show function in it, returning String
<orbitz> which really suck sif you want Showable and Orderable
<Alpounet> Yeah, true :-p
<orbitz> ala hadoop code
<orbitz> whcih is Writable, Comparable, and WritableComparable
<Alpounet> you are obliged to inherit an interface from another in Java
<Alpounet> orbitz, what I mean is t hat you always have to describe the interface in a named "type interface" (interface, typeclass)
<orbitz> so structural polymorphism sound slike safe ducktypign to em
<Alpounet> orbitz, that's it, exactly
<Alpounet> (for me... FWIW)
<orbitz> so this structural polymorphism is true for modules too (in the case of functors)?
<Alpounet> I don't remember if it's actually true.
<Alpounet> Actually, right now, I'm pretty sure we can't.
<Alpounet> We always have to give a module signature IIRC, when defining a functor.
<Alpounet> Wait 2 seconds, I'm looking for my OCaml book :-p
<Alpounet> Yeah, we are obliged to provide module signatures for all the parameters of our module functor.
<Alpounet> But still, module functors are powerful :-)
<Alpounet> Polymorphic variants too !
<orbitz> what are polymorphic variants?
<Alpounet> too long to explain, sorry :-p
<orbitz> so with polymoprhic variants, does this mean I can have type foo = Wubba, in seperate moduels, and write a funciotn that can match `Wubba from either module?
<Alpounet> not really
<Alpounet> well you can