watermind has quit [Quit: Konversation terminated!]
cdidd has quit [Ping timeout: 252 seconds]
milosn has quit [Ping timeout: 244 seconds]
milosn has joined #ocaml
hcarty has quit [Ping timeout: 245 seconds]
hcarty has joined #ocaml
xaimus has quit [Ping timeout: 264 seconds]
emmanuelux has quit [Ping timeout: 248 seconds]
mcclurmc has quit [Ping timeout: 252 seconds]
madroach has quit [Ping timeout: 244 seconds]
madroach has joined #ocaml
mcclurmc has joined #ocaml
doomrobo has joined #ocaml
<doomrobo>
How would I to write a function that takes either a record or a class that had a function (whether it be a method or a field) called, say, "foo" and executes it with a unit parameter?
<mk270>
wmeyer: success - it now reliably locks up the X server
<wmeyer>
mk270: cool!
<doomrobo>
let x = {foo = (fun () -> print_endline "foo")};;
<mk270>
wmeyer: it can even take out the *other* X server on the machine
<mk270>
which is impressive
<doomrobo>
and let y = object method foo = print_endline "foo" end;;
<mk270>
need a hard reboot - caps lock, alt+ctrl+f1, etc, not wokring
<doomrobo>
how would I write a function that runs foo() in both x and y?
<wmeyer>
doomrobo: it's not possible, it's different type
<wmeyer>
mk270: how many lines is it?
<doomrobo>
wmeyer, what about matching to the type of the argument?
<wmeyer>
is it somewhere?
<wmeyer>
doomrobo: not possible to match types, limited way is to GADTs
<doomrobo>
GADTs?
<mk270>
oh it crashes around the fifth line
<mk270>
i mean, there's no actual code yet
<wmeyer>
yes
<wmeyer>
doomrobo: it's advanced topic
<doomrobo>
I don't know what that means
<doomrobo>
ok
<mk270>
it'll be about a hundred lines long when i'm done
<wmeyer>
doomrobo: generally it's not needed
<doomrobo>
just wondering
<mk270>
but there's a LOT of Xlib that needs gluing into ocaml
<wmeyer>
ask adrien he's created cowboy to generate automatically C bindings looking at headers (AFAIK)
<wmeyer>
maybe you can use some meta programming techniques instead of doing all by hand
<mk270>
but that means we lose the fun of segfaults in ocaml
<mk270>
where's your sense of irresponsibility, and danger? :)
<wmeyer>
doomrobo: you can use functors do it, just provide an interface that represents the accessor function to your object or record
<wmeyer>
mk270: you got me! yes, bad advise - do it by hand :)
ontologiae has quit [Ping timeout: 260 seconds]
<wmeyer>
choose your poison, meta programming or human meta programming
<doomrobo>
wmeyer, that would work, I suppose
<wmeyer>
yes, you could use before mentioned techniques too - but i limited number of times i can use word "meta" on this channel
<wmeyer>
all I mean is "generating code" by writing code, no other meaning :-)
<doomrobo>
now for a n00bier questions:
<doomrobo>
I write: let y = object method foo = print_endline "foo" end;;
<doomrobo>
then it tells me when I do y#foo () that it's not a function
<wmeyer>
strip ()
<doomrobo>
I'm trying to call the function
<doomrobo>
not see its type
<wmeyer>
methods have always implicit unit when they have empty number of args
<wmeyer>
you say y # foo
<doomrobo>
but functions don't have the implicit unit?
<mk270>
doomrobo: some background on what the ultimate goal here is might be useful
<wmeyer>
because OCaml things you meant let y = object method foo () = print_endline "foo" end;;
<doomrobo>
mk270, none, just trying to grasp this
<wmeyer>
but with functions it's different you have to say () if you want to turn the variable to function
<wmeyer>
it's pretty consistent actuallt
<mk270>
doomrobo: excellent! :)
<doomrobo>
wmeyer, so how do I get the variable from the object?
<doomrobo>
just write the object?
<doomrobo>
and look for the variable inside it?
<wmeyer>
doomrobo: use val my_variable = []
<wmeyer>
or mutable val my_variable = true
<wmeyer>
then you can acces them via. my_variable <- [42]
<wmeyer>
in the method
<wmeyer>
you can't access variables outside the methods of the object
<doomrobo>
wmeyer, I was asking how I can see the type of a method
<wmeyer>
so all you can is to use methods
<doomrobo>
I have a method that takes no arguments and I want to see its type signature from the REPL, how do I do this?
<wmeyer>
ah, type of method is defined either by row type or with method key word
<mk270>
do you not get that information by pasting the class into the toplevel?
<wmeyer>
just send your piece of code to repl, but whole class or object not a single method
<wmeyer>
s/repl/toplevel/ ;-)
<doomrobo>
I see. So I do have to look at the whole object to see the method
<doomrobo>
how is that consistent with functions requiring ()?
ftrvxmtrx has joined #ocaml
<wmeyer>
sure, methods don't make sense alone
<wmeyer>
method is not a function
<wmeyer>
it needs object
<doomrobo>
gotcha
<doomrobo>
now it makes sense
<mk270>
doomrobo: do you understand what () represents?
<doomrobo>
yes
<mk270>
ok
<doomrobo>
wmeyer, how would I pass a method as a first class value to a function that takes a callback?
<doomrobo>
is that possible? I'm assuming that methods can somehow be treated as functions
<wmeyer>
doomrobo there is bridge with methods - you can curry/uncurry them
<wmeyer>
yes
<doomrobo>
show me the way
<wmeyer>
utop[1]> object method bar = () end;;
<wmeyer>
- : < bar : unit > = <obj>
<wmeyer>
;;
<wmeyer>
it has row type unit
<wmeyer>
utop[4]> class foo = object method bar = () end;;
<wmeyer>
class foo : object method bar : unit end
<wmeyer>
<wmeyer>
utop[5]> class foo = object method bar () = () end;;
<wmeyer>
class foo : object method bar : unit -> unit end
<wmeyer>
<wmeyer>
utop[6]> new foo # bar;;
<wmeyer>
- : unit -> unit = <fun>
<wmeyer>
<wmeyer>
utop[7]> new foo # bar ();;
<wmeyer>
- : unit = ()
<wmeyer>
<wmeyer>
utop[8]> class foo = object method bar n = n+1 end;;
<wmeyer>
class foo : object method bar : int -> int end
<wmeyer>
utop[9]> List.map (new foo # bar) [1;2;3;4];;
<wmeyer>
- : int list = [2; 3; 4; 5]
<wmeyer>
weie has joined #ocaml
<doomrobo>
okay, let me see if I get this
<wmeyer>
ok
<wmeyer>
doomrobo: why do you need objects?
<doomrobo>
I'm not doing anything right now but trying to understand this language
<wmeyer>
very good
<wmeyer>
yes, it might be good idea to experiment
<doomrobo>
so first question: are you redefining foo three times?
<wmeyer>
i understood objects when implemented some custom GUI library
<wmeyer>
in toplevel it's allowed
<wmeyer>
not when compiling
<doomrobo>
I come from C, C++, and Python, objects are pretty natural to me, but in Python, methods are functions (IIRC)
<wmeyer>
doomrobo: I came from C++ mostly :-)
<wmeyer>
doomrobo: types need special treatment
<doomrobo>
so in utop[7] you're partially applying foo#bar?
<wmeyer>
i think the object system pretty much fits into the language without big hurdle
<wmeyer>
in utop 6 yes
<doomrobo>
no, 7
<wmeyer>
in 7 actually the method is called
<doomrobo>
o, no
<doomrobo>
right
<doomrobo>
6 isn't partially applying, though
<doomrobo>
that's just the method itself
<doomrobo>
isn't it?
<wmeyer>
the reason i asked why you want objects is that they quite hard at the begining, no other reason, also most Camlrs tend to avoid them. It's an art to recognise patterns they are useful.
<wmeyer>
no the signature tells you it's a function
<wmeyer>
- : unit -> unit = <fun>
<wmeyer>
<wmeyer>
function that takes unit and returns unit
<doomrobo>
yes, so when you call foo#bar without the parameter (the only parameter), you're just being given the type of the function, no?
<wmeyer>
yep
<doomrobo>
so that's not partial application
<wmeyer>
that is a function
<doomrobo>
that's just the function
<wmeyer>
partial application of a method on ab object
<doomrobo>
oh, I misspoke. So that *is* a function
<doomrobo>
OH
<wmeyer>
method ~ function
<doomrobo>
that's cool
<doomrobo>
very interesting
<doomrobo>
so how do I partially apply a method without arguments?
<wmeyer>
yes
<wmeyer>
answer is you can't directly, but you can via lambda abstraction
<doomrobo>
basically this:
<mk270>
aha, i wasn't trying to get the defaultrootwindow. oops :)
<doomrobo>
(fun args -> object#method args)?
<wmeyer>
(fun () -> o # your_method)
<wmeyer>
yes
<doomrobo>
yeah
<wmeyer>
actually not args
<wmeyer>
arg
<doomrobo>
or just nothing
<doomrobo>
(unit)
<wmeyer>
(fun x y z -> o # your_method x y z)
<wmeyer>
but then you can do it directly
<wmeyer>
or just provide a method with unit
<doomrobo>
yeah
<wmeyer>
accepting unit
<wmeyer>
then you can partially apply always
<doomrobo>
how do I write a function that takes a variable number of arguments
<wmeyer>
this syntax sugar just makes them more natural
<wmeyer>
you can't really, what you can do is to use optional arguments
<doomrobo>
I think I'll always put () on my methods
<doomrobo>
suppose I want a dump function
<doomrobo>
that prints all arguments
<doomrobo>
can't do it?
<wmeyer>
can't
<wmeyer>
but you can
<doomrobo>
or must take a list and then
<wmeyer>
yes
<doomrobo>
alright
<wmeyer>
but list is just single type
<doomrobo>
exactly
<doomrobo>
I was about to say it looks like two birds with one stone
<wmeyer>
but there are methods for this GADTs and Hlists
<doomrobo>
1. No new syntax 2. Uses lists to keep the types the same
<wmeyer>
so, type system does not support overloading
<wmeyer>
just use different name :-)
<doomrobo>
I just read a long thread on multiple dispatch and lack thereof in OCaml vs Java
<wmeyer>
such type system comes with cost
<wmeyer>
but on other hand brings you to completely different level of programming
<wmeyer>
but btw. Scala has nice support for objects
<wmeyer>
slightly different apporach
<wmeyer>
and supports overloading
<wmeyer>
with cost of function level annotations
<doomrobo>
I was actually looking into Scala as something to learn
<doomrobo>
decided not to
<wmeyer>
to be honest I quite like Scala, but I love OCaml
<wmeyer>
quite like >> like.
<wmeyer>
when you need to write for JVM is probably good choice
<doomrobo>
not Clojure?
<wmeyer>
Clojure is lisp, comes with different abstractions and different problems
<wmeyer>
Clojure does not have type system
* doomrobo
likes Scheme...a lot
* wmeyer
appreciates Scheme
<mk270>
i found a version of Racket which has an ocaml-like typesystem
<mk270>
a hashlang or whatever it's called
<wmeyer>
mk270: typed-racket that is
<doomrobo>
typed racket
<mk270>
that seemed to me to be absolutely bearable
<doomrobo>
it was decent
<doomrobo>
I liked it
<mk270>
ah, i think this was an extension to typed-racket
<mk270>
#lang plai-typed or
<mk270>
thereabouts
<mk270>
basically, sriram krishnamurti trying to get the best of both worlds
<wmeyer>
power of macros that is
<mk270>
he has huge hardon for lisp, but likes the ml type system
<doomrobo>
I was actually wondering about macros in ML
<doomrobo>
ML has a very expressive matching system
<doomrobo>
so can't you implement things like macros simply using the matching?
<wmeyer>
doomrobo: they are limited, camlp[4 5] would be your best bet
<wmeyer>
but they are still fairly powerful
<doomrobo>
interesting
<wmeyer>
doomrobo: you can, but not everybody is brave enough
<mk270>
there's no *shame* in getting lisp macros wrong and asking for help. camlp4 on the other hand, you can't just say "oh, how does this work"
<wmeyer>
so true
<doomrobo>
I wouldn't know
<doomrobo>
so union types don't exist here?
<wmeyer>
they exist, you write macros in ocaml
<wmeyer>
maybe let's say syntax extensions to be on a safe side :-)
<mk270>
wmeyer: thanks - i am familiar with those issues, but not seen them laid out clearly together before
<doomrobo>
got it
<doomrobo>
so let's see
<mk270>
wmeyer: ocaml seems to have a similar problem in relation to toolchains - everyone wants his own dpkg, apt-get, autoconf, make, etc
<wmeyer>
yep
<wmeyer>
we call it, "rule of four", funny term we have invented on OUR during the dinner out
<mk270>
meaning?
<mk270>
OUR?
<wmeyer>
OUD
<mk270>
OUD?
<wmeyer>
yes
<mk270>
what is OUD?
<wmeyer>
ocaml has four stdlibs, four build systems, and four package managers
<mk270>
is it Oxford University (Detroit)?
<wmeyer>
it was a conference after ICFP
<mk270>
ah ok
<mk270>
well yes
<wmeyer>
and each of them contain at least one genius idea :)
<wmeyer>
but ...
<wmeyer>
well, now the situation is way better
<mk270>
explain
<wmeyer>
taking ocamlbuild, it has a really nice ideas in it
<wmeyer>
but on other hand it looks like it has some bugs
<mk270>
i'd rather have lots of tiny libs, rather than batteries, jane street, citrix and whoever's massive stdlibs
<wmeyer>
take ExtLib maybe a nice idea to drop on top of stdlib - but also not maintained
<Qrntz>
I ended up re-inventing my own tiny lib
<mk270>
python had this problem with frameworks
<Qrntz>
I'll probably make it public when I make any of my projects that depend on it public
<wmeyer>
I mean mostly fragmentation and lack of man power to do the right thing, but it's so much improved these days
<mk270>
whereas ruby is *horizontally integrated* and has one web framework, rails, which sucks
<mk270>
i mean, one sucky framework. the fact that there is only one is awesome
<mk270>
even though i believe in freedom and forking and so on
<Qrntz>
what about Sinatra and Goliath?
<mk270>
well, it needs to improve a HELLUVA lot more
<mk270>
qrntz: never heard of them
<Qrntz>
meh
<mk270>
and i'm sure people outside python have never heard of *any* python frameworks
<mk270>
in ocaml the problem is much more fundamental
<mk270>
as it affects the toolchain as well as the libraries
<wmeyer>
mk270: it's changing
<mk270>
wmeyer: explain?
<wmeyer>
this is a perfect situation, people will come to the community to help
<mk270>
?
<mk270>
well, i am here largely to help
<wmeyer>
is way better, looking at Oasis, OPAM, Core, Batteries
<mk270>
i.e., send pull requests to whoever looks like they're doing the right thing
<mk270>
what i would like
<mk270>
is for the ocaml labs poeple at cambridge to say "for 2013, we recommend tool X for distribution, tool Y for build/config, and we don't recommend any stdlib"
<mk270>
but i have no idea of the social/politics of it all
<wmeyer>
well, we are getting there really
<wmeyer>
the static type system is a blessing :)
<wmeyer>
we can find bugs and improve libraries or tools quicker
<wmeyer>
and with reduced amounts of time that would be needed in case of Python or Ruby
<mk270>
good to hear
<mk270>
reassuring
<wmeyer>
I really believe in this
<wmeyer>
because i see how much move is these days
<wmeyer>
if you didn;t neeed to the compiler would know in advance
<doomrobo>
I suppose that's the case
<wmeyer>
yep
<doomrobo>
great
<mk270>
doomrobo: these capitalised data constructors are a little weird in ocaml, compared to other languages
<doomrobo>
yeah
<Qrntz>
it's an FP concept, I wouldn't call it OCaml-specific
<Qrntz>
s/an/a/
<doomrobo>
a typed FP concept
<Qrntz>
indeed
<Qrntz>
to be fair, you can have sum types in e. g. C as well
<Qrntz>
they're just not as pervasively used and less comfortable to use, too
<doomrobo>
wmeyer, so either is defined as the union of record_type and object_type and in that definition I must supply the names of constructors to convert any of those types into the supertype, which is either. Then, when I create a function that takes this type. So what is the matching doing when it's matching the either type?
<doomrobo>
is the matching part idiomatic or is there reasoning to it?
<Qrntz>
doomrobo, deconstructing the constructor and binding the arguments
<doomrobo>
so the match deconstructs either
<doomrobo>
and the compiler knows what it used to be
<doomrobo>
before it was casted to either
<Qrntz>
no, it's not like that
<mk270>
qrntz: i meant whether that sort of constructore was a first-class citizen
<mk270>
but this really isn' tmy area :)
<doomrobo>
Qrntz, explain
<Qrntz>
mk270, ah, I see
<Qrntz>
doomrobo, sure
<Qrntz>
OCaml eliminates types at compile-time
<doomrobo>
so how does it deconstruct either?
<Qrntz>
at runtime, ADT constructors without parameters («type direction = Left | Right») are represented as integers
<doomrobo>
ADT?
<wmeyer>
doomrobo: Algebraic Data Types
<Qrntz>
ADT constructors with arguments are represented as tagged tuples, where the tag indicates which constructor it is and the fields contain the arguments
<wmeyer>
doomrobo: types that consists of sum and products
<doomrobo>
you lost me
<wmeyer>
the alternative is sum the product is a tuple
<Qrntz>
algebraic data types, sum types, tagged unions
<Qrntz>
they're called different names
<doomrobo>
I get tagged unions
<doomrobo>
they're all the same?
<Qrntz>
in which sense?
<Qrntz>
ah, the definitions
<doomrobo>
did you just say they're all the same?
<wmeyer>
doomrobo: same
<doomrobo>
ok, so Record is represented as an integer
<wmeyer>
maybe ADT are just most formal term
<Qrntz>
technically, sum types and product types are both subsets of algebraic data types
<doomrobo>
Qrntz, right?
<Qrntz>
so sum type or tagged union is the proper name and ADT is the more general one but still acceptable
<Qrntz>
(it's uncommon to refer to a product type as ADT in OCaml)
<doomrobo>
Qrntz, so you were saying about deconstructing union types...
<Qrntz>
sum types, yes
<Qrntz>
I don't think I know another way to explain that
<doomrobo>
Qrntz, you were explaining how match with works
<mk270>
doomrobo: out of interest, what sort of progamming languages were you familiar with before you tried ocaml?
<mk270>
wmeyer: that essay is superb. to what extent do you think ocaml suffers from a similar curse?
<Qrntz>
doomrobo, I'll have to explain some of OCaml's internals if that's fine with you
<doomrobo>
shoot
<Qrntz>
OCaml represents everything as either a long (immediate value — ints, bools, chars, zero-arity data constructors) or a block (array, tuple, list, multi-arity data constructors)
<Qrntz>
what's of interest to us now is multi-arity data constructors
<Qrntz>
the order of multi-arity data constructor definitions in a type definition of a sum type defines the numbering of their tags
<wmeyer>
mk270: it's similar but not bad as lisp, actually perhaps the social problems described don't exist
<doomrobo>
that was a mouthful
<doomrobo>
Qrntz, got it
<doomrobo>
continue
<mk270>
wmeyer: the social problems don't exist?
<Qrntz>
a «match … with …» statement matches the tag (I'm afraid I won't be able to explain how exactly) of the data constructor and based on that, proceeds to bind the values it encompasses to the variables you declared in a match statement
<wmeyer>
mk270: as described there no
<wmeyer>
but how many pre-processors we have
<Qrntz>
at runtime, a multi-arity data constructor is just a tagged tuple
<wmeyer>
currently four.
<Qrntz>
so that's a bit like deconstructing a tuple, which I suppose is already familiar to you
<doomrobo>
yes
<doomrobo>
ok, I think I get it
<doomrobo>
but why do you have to include the constructors?
<doomrobo>
why not write the types instead?
<doomrobo>
also, how does this work with more than one layer of types?
<Qrntz>
I'm not sure I got that right
<mk270>
wmeyer: is someone gradually chipping away the "four of everything" problem?
<doomrobo>
suppose I have 3 subtypes and I want to match it with the deepest one
<doomrobo>
would it deconstruct the whole tuple looking for it, or would it error?
<Qrntz>
doomrobo, example code?
<doomrobo>
four of everything?
<doomrobo>
Qrntz, I don't think I could
<Qrntz>
I don't get the deep type metaphor
<doomrobo>
Suppose I have a type that is a sum type of two other types
<Qrntz>
besides, you're accessing values, not types
<wmeyer>
mk270: it turns to that the magic number in most cases is four.
<Qrntz>
okay
<doomrobo>
now suppose I have another type that's a sum type of two other types
<doomrobo>
now suppose I have nother type that is a sum type of the two other sum types
<doomrobo>
now suppose I give that biggest sum type as an argument to a function which then tries to match it with the original 4 types
<doomrobo>
would that work?
<wmeyer>
mk270: as you say, we don't have much documentation for instance
<Qrntz>
not at all
<doomrobo>
why?
<mk270>
wmeyer: we're almost at four websites! :) inria, ocaml.org, github, ocamlcord
<Qrntz>
sum types don't have subtyping unless they're polymorphic (and those are a bit of an advanced topic)
<wmeyer>
mk270: because people flipping code so quickly that they don't pay attention to manuals, on other hand usually libraries are single man projects. Not like in Java
<Qrntz>
so, all three definitions would be disjoint
leoncamel has joined #ocaml
<doomrobo>
Qrntz, what's this with subtyping?
<wmeyer>
in Java effort is significan so each library is like gem
<mk270>
wmeyer: it really does sound similar to the "language so expressive every one-man-band does his own thing"
<Qrntz>
doomrobo, let us suppose that we have a sum type №1 that's defined as «type number = Int of int | Float of float»
<wmeyer>
mk270: and in Java you don't want your 20KLOC library fall to nowhere
<Qrntz>
… a sum type №2 defined as «type collection = SArray of string array | SList of string list»
<wmeyer>
in OCaml is accepted that 700LOC library can be dropped because documenting that would be boring of course
<wmeyer>
acceptable
<mk270>
mm
<Qrntz>
… a sum type №s defined as «type somethingelse = Collection of collection | Number of number» ;;
<mk270>
so long as these problems are well understood by the folks trying to fix the system, i'm happy
<Qrntz>
er
<wmeyer>
mk270: but actually I can say we have a lot of high quality libraries
<Qrntz>
s/№s/№3/
<Qrntz>
all those are disjoint, your function can only match on one sum type at once
<Qrntz>
but
<Qrntz>
deconstructing the parameters to their respective sum types and to the primitive types they carry
<mk270>
wmeyer: indeed, though i'd prefer a lot more *-{amqp,sql}-lwt
<Qrntz>
so e. g. you could have a function «let f = function Collection c -> (print_endline "collection"; match c with SArray s_ary -> Array.iter print_endline s_ary | …»
cdidd has quit [Remote host closed the connection]
yeahOh has joined #ocaml
<yeahOh>
what do you guys think about haskell?
<companion_cube>
it's interesting ;)
<yeahOh>
lol
nickmeharry has quit [Quit: Leaving.]
<gour>
yeahOh: i tried it...now i'm here :-)
<companion_cube>
it's quite fun, but I prefer to be able to use dirty, imperative hashtables
suyu has left #ocaml []
<pippijn>
haskell tends to have laziness leaks
suyu has joined #ocaml
<pippijn>
so you end up writing strictness annotations everywhere
<pippijn>
making your code look ugly
<gour>
yeah, haskell seems to quickly lose its 'purity magic' when you encounter real-world
<wmeyer>
my opinion is that the problem with haskell is not purity, but laziness
<pippijn>
which is what I tried to say, yes
<gour>
wmeyer: i agree, what i meant with 'purity magic' is that one expects that the code wold look beautiful in practice, but then one has to devise all kinds of workarounds due to unexpected performance glitches (mostly due to laziness)
<wmeyer>
gour: so purity comes in pair with laziness yes, mostly due to performance reasons
<wmeyer>
but explicit laziness is way better
<wmeyer>
(some people that have done a lot of haskell will say otherwise)
<gour>
otoh, i do not like to think about monada just to perform some IO...that's why we like OCaml
<pippijn>
I like monads for IO
<gour>
it's enough to take a look at language-shooutput entries and see how the code looks like
<wmeyer>
I like monads.
<gour>
maybe i'll start loving 'em in ocaml as well :-)
<pippijn>
I use monads for async IO in ocaml
<wmeyer>
they force you to write high level code, and the IO code is clearly separated
<adrien>
"At 28C3, Klink and Waelde showed that a number of technologies (PHP, ASP.NET, Ruby, Java, Python, etc.) were vulnerable to the decade-old hash-flooding DoS attacks. The vulnerability was then often fixed by adopting stronger hash functions and "randomizing" them."
<adrien>
"We show that it's not enough, at least for systems relying on "MurmurHash" or on Google's "CityHash64", by presenting powerful "universal multicollision" attacks for those functions."
<adrien>
:P
<wmeyer>
I'm actuall against hashtbls.
<companion_cube>
I love hashtables
* wmeyer
thinks hash functions should occur only in DB
<adrien>
don't throw untrusted data in such a datastructure =)
<companion_cube>
I think batteries has a reimplementation of Hashtbl with balanced trees rather than lists in the buckets
<companion_cube>
it would be extremely interesting to have splay trees, also, imho
<wmeyer>
that sounds reasanoble
ontologiae has joined #ocaml
cdidd has joined #ocaml
cdidd has quit [Remote host closed the connection]
nickmeharry has joined #ocaml
cdidd has joined #ocaml
<flux>
maybe there could even be a bit wasted for 'is it a list, is it a tree'
<flux>
as small lists are likely faster than trees
cdidd has quit [Ping timeout: 245 seconds]
ikaros_ is now known as RagingDave
cdidd has joined #ocaml
RagingDave is now known as ikaros
ikaros has quit [Quit: Ex-Chat]
RagingDave has joined #ocaml
cdidd has quit [Remote host closed the connection]
RagingDave is now known as RagingDave_
RagingDave_ is now known as RagingDave
RagingDave has quit [Quit: Ex-Chat]
RagingDave has joined #ocaml
jamii has joined #ocaml
watermind has quit [Quit: Konversation terminated!]
<companion_cube>
flux: it's not that evident, after all, lists are also trees
<wmeyer>
every recursive data structure is tree, but I would suggest saying onle these which branch should be trees
<companion_cube>
replacing lists by trees in a hashtable's buckets also makes the DDos attacks less efficient
watermind has joined #ocaml
cdidd has joined #ocaml
cdidd has quit [Read error: Connection reset by peer]
shp has joined #ocaml
cdidd has joined #ocaml
<shp>
hi
<shp>
it looks like camllight interpreter does not like this line: "if !resultat <> !objectif then" because if I do "camllight < myCode.ml" with this, the interpreter freezes, and if i replace "!resultat" by "2" for instance, it works perfectly
<Qrntz>
shp, seeing as Caml Light has been obsolete for a very long time I'm not sure you'll get much support (just saying)
<doomrobo>
so I understand what mistake I was making yesterday
<doomrobo>
I thought that match with Int a was working
<doomrobo>
which it wasn't
<shp>
Qrntz: with ocaml i get many errors
<shp>
so i'm not gonna change :/
* Qrntz
shrugs
cdidd has quit [Ping timeout: 245 seconds]
jamii has quit [Ping timeout: 255 seconds]
<doomrobo>
how do you overload the comparison operators? >, <, <=, >=, ==, !=
<Qrntz>
you don't
<Qrntz>
they are polymorphic already
<wmeyer>
doomrobo: you can define any infix operator with like (<) if you wish as a function, in these case you lose polymoprhism
<wmeyer>
(they are written as C builtins)
<doomrobo>
so how would I keep the polymorphism but just add a type to its list of things it can compare
<doomrobo>
like int * int
wormphle1m has quit [Read error: Connection reset by peer]
<wmeyer>
doomrobo: for each of the modules in theory you could define it own set of operators and the explicilty open locally module to use them
<doomrobo>
so the answer is "there is no way"
wormphlegm has joined #ocaml
<wmeyer>
doomrobo: you can't. OCaml so far has no overloading, these operators are defined as 'a -> 'a -> bool
<doomrobo>
but they obviously match over the type of 'a
<wmeyer>
doomrobo: but because runtime knows how to traverse the structures it can traverse and compare
<doomrobo>
how does it compare objects?
<wmeyer>
look at compare.c, hash.c, intern.c and extern.c
<wmeyer>
the same way as GC traverse the memory
<wmeyer>
comparision is very rough, it's a literal comparion of fields in the blocks, not maybe byte by by byte but carrying some minimal information about the size of the object or rough type, using tags that define it
<Qrntz>
doomrobo, it can compare any type, regardless of how it is defined
<doomrobo>
and I am unable to redefine it without destroying the current definition of compare?
<Qrntz>
any re-definition shadows the previous one
<Qrntz>
but…
<Qrntz>
you could define a set of comparison operators in a module and open it locally
<wmeyer>
well as you discovered you can't match the type
<doomrobo>
what do you mean, wmeyer
<wmeyer>
you can't say the set of types belong to a class that has some interface
<wmeyer>
that either you have full polymorphism or nothing
<Qrntz>
no type classes
<wmeyer>
or concrete type
<doomrobo>
I don't think I'm following...
<Qrntz>
well, there's structural typing for objects
<Qrntz>
and subtyping for polymorphic ADTs, yadda yadda yadda
<Qrntz>
if you have a specific aim to do something, ask away in details, if not, it can be a very long conversation
<doomrobo>
wmeyer, could you explain what you said "you can't say the set of types belong to a class that has some interface" with code that would fail?
<troydm>
can i have same label names in same module but in different types
<troydm>
like
<troydm>
type a = { f : float }
<troydm>
type b = { f : float }
RagingDave has quit [Quit: Ex-Chat]
<troydm>
?
<doomrobo>
yes
<Qrntz>
no
<doomrobo>
what?
<Qrntz>
try it
<troydm>
hmm i get mixed up error
<Qrntz>
right.
<doomrobo>
Qrntz, it works for me
<troydm>
so basicly i can't have it?
<doomrobo>
Qrntz, it just takes the last type that I defined it as, namely b
<Qrntz>
the question was about same label names, not same type definitions (that just shadows the earlier type)
<troydm>
is there a way to have same labels in different records in same module?
<troydm>
i just don't want to spawn tons of labels
<Qrntz>
not currently, there's development going in that regard which we'll probably see in 4.00.2 or later
<Qrntz>
the common workaround is to prefix the label name with something that signifies the type the record is a member of
<troydm>
yeah that's what i call tons of prefix names
<doomrobo>
Qrntz, what was his first question, then? Aren't labels just for functions?
<Qrntz>
you seem to be confusing labeled parameters and record labels
<doomrobo>
that's it
<doomrobo>
so what was he asking?
<troydm>
i was asking about record labels
<doomrobo>
if you could have the same record label name but with different types
ontologiae has quit [Ping timeout: 252 seconds]
<troydm>
doomrobo: yeah
<troydm>
but not specificly that
<troydm>
i wanted something like
<troydm>
type a = { f : float; i : int }
<troydm>
type b = { f : float; s : int }
<troydm>
etc
<doomrobo>
doesn't that work?
<troydm>
no
<troydm>
it compiles alright
<troydm>
but as soon as you start writing functions
<troydm>
it mixes up labels
<doomrobo>
how?
<troydm>
well it says error
<troydm>
f is label related to b
<doomrobo>
can you give code? I'm very confused
<troydm>
in a record creation where i create a type record
<troydm>
try writing those to types in ml file
<doomrobo>
I did
<troydm>
and then write something like
<troydm>
let _ = { f=0.0; i=1 }
<troydm>
and then try compiling that file
<doomrobo>
ok
<doomrobo>
interesting
<doomrobo>
why does it mix it up? they're two distinct types
<doomrobo>
well, not really
<doomrobo>
but they're distinct labels of equal types
<wmeyer>
doomrobo: so - at the moment - you need to either prefix the labels or put into separate modules, and reference with a module name - but putting into modules is not always possible in a presence of recursive types
<doomrobo>
ok
<wmeyer>
type inference however could work out the right type in most cases perhaps using some heuristics
pkrnj has joined #ocaml
<doomrobo>
wmeyer, if I wanted to do a compare without shadowing the Persasives.compare, would it be okay style to make a compare method for objects?
<wmeyer>
for objects method would be OK
<wmeyer>
but not for the reason of not shadowing compare in pervasives
<wmeyer>
usually some modules contain custom compare, as long as you don't open the module it's OK
<mk270>
anyone here good on ocaml-c bindings?
<wmeyer>
mk270: it depends what's is the question about binding to C
<mk270>
question is "oh, why is it segfaulting?"
<mk270>
basically, i have a value which seems to become the null pointer without warning, despite efforts to the contrary
wormphle1m has joined #ocaml
wormphlegm has quit [Ping timeout: 260 seconds]
gour has quit [Quit: WeeChat 0.3.8]
shp has quit [Quit: kit]
iratsu has quit [Remote host closed the connection]
doomrobo has quit [Quit: Leaving]
weie has quit [Quit: Leaving...]
<wmeyer>
mk270: GC can move the pointers on the heap, or make them invalid. It moves or dealocates during compaction after minor collection. Collection happens when GC is being requested for the new block. Therefore you need to register the local variables on your stack frame with special macros, the same for the arguments. Second, there are two types of allocation, one will never trigger collection and is uses when you are assigning t
<wmeyer>
fields several heap allocated values, the second one does not prevent GC to perform collection.
<wmeyer>
Local variables need to be registered to make sure that they are being referenced by the global roots, so GC know it can't collect them because you use it.
<wmeyer>
if you read the carefuly and understand it should be fine
<wmeyer>
don't debug seg faults, just stick to the rules.
<wmeyer>
Good luck.
iratsu has joined #ocaml
mye has joined #ocaml
<wmeyer>
mk270: it's not easy, I had hard times with it, but fairly easy later on when you understand how it all works, and why you need to apply these rules
mye has quit [Client Quit]
tane has quit [Quit: Verlassend]
mye has joined #ocaml
mye has quit [Quit: mye]
mye has joined #ocaml
eni has quit [Quit: Leaving]
<mk270>
wmeyer: thanks - i shall keep trying, but it is taking a lot of time and effort
<Qrntz>
mk270, if you need a value that the GC shan't touch, you can allocate it out of the heap (but don't forget to delete it later)
<Qrntz>
use caml_stat_alloc() for that
<mk270>
qrntz: cheers - it's not really clear what's going on :)
<mk270>
i suspect that there may be some C macros elsewhere in the library bindings i'm hacking on which are making the code behave in unexpected ways
* Qrntz
shrugs
<mk270>
how do i get source code to be visible in gdb?
<mk270>
is it gcc -g -ggdb? and if so how do i get ocamlopt to pass that on?
<Qrntz>
-ccopt -g
<mk270>
ah thanks
<troydm>
happy new year ocaml gurus!
<Qrntz>
cheers; happy new year to you as well!
<mk270>
what absurd timezone are you people in!? :)
<Qrntz>
UTC+2
<troydm>
UTC+4
<mk270>
i'm two blocks away from buckingham palace. this shit is kicking off
<mk270>
some absurdly rich people with their own private square have just flung a vast quantity of explosives into the atmosphere near my flat
<mk270>
(there's a big variation in incomes, street to street in inner london)
<mk270>
i couldn't afford to breathe over there, but thanks to the fireworks, no-one else can either :)
<mk270>
qrntz: thanks, gdb has come in handy
hcarty has quit [Ping timeout: 244 seconds]
hcarty has joined #ocaml
<wmeyer>
troydm: Just had a beer! Happy new year!
<troydm>
cheers :)
<wmeyer>
mk270: gdb will not help you too much in a case of collections.
<wmeyer>
but it's helpful sometimes
<mk270>
it was useful to see where the problem was occurring
<mk270>
i.e., better than ltrace
<mk270>
let's say i have a function which returns some value which is a wrapper around a structure it got from C
<mk270>
in this case, th ereturn value of XOpenDisplay
|jbrown| has quit [*.net *.split]
pango has quit [*.net *.split]
jave has quit [*.net *.split]
tizoc has quit [*.net *.split]
so has quit [*.net *.split]
tizoc has joined #ocaml
<mk270>
that could get gc'ed slightly before i'm done with it, when the connection is still open, right?
pango has joined #ocaml
|jbrown| has joined #ocaml
jave has joined #ocaml
<mk270>
do i need Abstract_tag or something similar?