<mattam>
well, adding (fun x -> ) isn't to much hassle, and it's not a common thing
<phubuh>
in this particular case, i have a pretty long list, and (fun s -> On_something s) is duplicated a lot :/
<mattam>
you mean you've got lot of different On_something ?
<phubuh>
yeah
<mattam>
hmmm, maybe using Variants could help then
<phubuh>
ah, you mean `These_things?
<mattam>
yep
<phubuh>
i should read about them :/
<mattam>
if you can, you could have a big fun like: fun construct v s = match v with `ThisOne -> `ThisOne s | `Another -> `Another s) and call List.map (construct `ThisOne) list
<phubuh>
ah
<phubuh>
yeah, that might be possible
<phubuh>
hmm. how would i make a function that calls another one and returns true if it did not raise a specific exception, and false if it did?
<mattam>
(fun f -> try f (); true with Exc -> false) ?
<phubuh>
ah, of course! thanks!
* mattam
is prompt and happy at coding caml as he worked on asm routines all day long
<phubuh>
ouch! :/
<Maddas>
:-/
<mattam>
:)
brwill_nearby is now known as brwill
TimFreeman has joined #ocaml
TimFreeman has left #ocaml []
foxster has joined #ocaml
brwill is now known as brwill_zzz
srv has joined #ocaml
bk_ has quit ["I'll be back"]
mattam has quit [zelazny.freenode.net irc.freenode.net]
teratorn has quit [zelazny.freenode.net irc.freenode.net]
mattam has joined #ocaml
teratorn has joined #ocaml
Xcalibor has joined #ocaml
<Xcalibor>
hiyas
<phubuh>
is there any way to create classes anonymously?
<Xcalibor>
?
<Xcalibor>
what use would that have?
<phubuh>
well, in java, a common sight is button.addMouseListener(new MouseAdapter () { void onButton (Event e) { ... } });
<phubuh>
i should refine my question to "is there any way to create subclasses anonymously"? :)
<Xcalibor>
a type class is a kind of interface class... you wouldn't be able to say newtype MyType = ... and then instance {} Myclass where ... ???
<Xcalibor>
well... okay, that's in haskell, sorry
<Xcalibor>
java uses anonymous subclasses because it doesn't have closures
<phubuh>
yeah, most of the time
<Xcalibor>
anonymous classes are a kludge to solve this problem
<phubuh>
i think anonymous classes are elegant
<Riastradh>
Xcalibor, but there are cases when it isn't a kludge to solve a stupid problem...
<Xcalibor>
in OCaml you simply give a closure as a call back and that solves it
<phubuh>
but anonymous classes can't only be used to implement callbacks
<Xcalibor>
Riastradh: yes, agreed, there's a small subset of all problems that they can solve
<Smerdyakov>
phubuh, so what's the particular situation where you want to use anonymous classes in OCaml?
<Xcalibor>
phubuh: other examples of uses?
<phubuh>
Smerdyakov, well, there is no particular situation :)
<phubuh>
i was playing around with the repl, and discovered that the object keyword can't be used outside of a class declaration, which makes the "class foo = object ... end" syntax a little confusing
<Smerdyakov>
phubuh, ah. So if you don't want to use such a feature, then you should be content to learn that it doesn't exist. :)
<phubuh>
i am :)
<Xcalibor>
phubuh: anonymous classes are a kludge for this reason: a class is a type and its associated actions (ie. data and an interface to talk to that data about its state)
<Xcalibor>
while an action can be anonymous, because it happens once, an object has a unique identity of its own... an anoynous class only lets you create limited objects for limited things... and it tries to supply what an anonymous action (ie. a lambda) would elegantly provide...
<Xcalibor>
that's why I say they are a kludge... they are bending the OO model to get a sort of functional benefit... mostly ugly, specially when you have to implement the Even interface methods and fill your anonymous class with "{}" empty methods
<phubuh>
# let f = let i = ref 0 in fun () -> incr i; !i;;
<phubuh>
val f : unit -> int = <fun>
<phubuh>
# f();;
<phubuh>
- : int = 1
<phubuh>
# f();;
<phubuh>
- : int = 2
<phubuh>
functions have state too :)
<Xcalibor>
phubuh: a closure is not a class (even when you can implement a OO system by using closures)
<Smerdyakov>
This discussion is pointless, I think.
<Smerdyakov>
The connection between closures and objects is very close.
<Xcalibor>
besides, your f has side-effects
<Xcalibor>
Smerdyakov: between closure and object, it is; between closure and class it is not
<Smerdyakov>
I don't think that's a meaningful comparison in this context.
<Xcalibor>
anyway, what you use the anonymous classes in Java you would use a lambda in OCaml (I cannot think of a situation where you wouldn't, I mean)
<Xcalibor>
Smerdyakov: agreed, but classes are object factories, and only objects by themselves by using a meta-grammar...
<phubuh>
when an object is used as a grouping of related closures with the same state, and i want to pass one such grouping to a function/method, but with modified behavior :)
<phubuh>
draw_model (new (object extend drawer method draw x = print_string "null drawer attempted to draw")) m
<phubuh>
(imagine that drawer has five other methods that i want to modify as well
<Xcalibor>
mmm...
<Smerdyakov>
How can I load a file into the OCaml interactive environment?
<Riastradh>
Bytecode-compile blah.ml and then '#load "/path/to/blah.cmo"'
<Smerdyakov>
Hm. OK!
<Smerdyakov>
"Unbound value load"
<Riastradh>
You didn't forget the octalthorpe, did you?
<Smerdyakov>
Ah, I did "forget" it. I thought it indicated the prompt.
buggs|afk is now known as buggs
<Smerdyakov>
Hm... I have a large, many-file OCaml project created by others, and I want to get all of its modules loaded in the repl so I can play with them. Is there any easy way to do this? :\
<Smerdyakov>
(The project is usually just compiled for command-line use.)
<Xcalibor>
Riastradh: octalthorpe?
<phubuh>
Xcalibor, #
<Xcalibor>
Smerdyakov: you should be able to create a repl which includes those modules by default the same way you can create one with the graphics module already loaded... it's somewhere in the docs
<phubuh>
if Unix.select reports that a socket is readable, but Unix.recv returns 0, does that indicate EOF?
<Xcalibor>
# is octalthorpe? curious alias, never heard it before... nice word :-)
<phubuh>
(Unix.recv is amazingly poorly documented)
<Xcalibor>
phubuh: some modules/functions are very poorly documented on-line... I guess the oreilly book makes a better work
<phubuh>
Xcalibor, ah, i'll check!
* Maddas
shrugs
<phubuh>
is the preliminary web version ok?
<Xcalibor>
phubuh: no idea, never checked sorry
<Maddas>
I didn't found the O'Reilly book too helpful for modules
<Smerdyakov>
Xcalibor, well, right now I'm performing the topological sort on the modules by dependencies manually.
<Riastradh>
Yes, # is an octalthorpe, not a hash sign, not a sharp sign, and _definitely_not_ a pound sign.
<Xcalibor>
Smerdyakov: whoa...
<Xcalibor>
Riastradh: so that's the official name? cool... in spanish has a lot of silly names as well... nobody seems to know which one is the right one, not even the Language Academy lol
<Xcalibor>
$ ascii '#'
<Xcalibor>
ASCII 2/3 is decimal 035, hex 23, octal 043, bits 00100011: prints as `#'
<Riastradh>
That is wrong; it is _definitely_ not a pound.
<Xcalibor>
some discrepancies... nevertheless it's a very cool name... it has 8 'pikes'
<Xcalibor>
i guess octothorpe comes from that fact
<Riastradh>
Yes, indeed.
<Smerdyakov>
Why is it not a pound?
<Riastradh>
The name 'pound' for it was invented by trucking companies or something and was only slang used by them, or something of that sort, if I remember correctly; there already _is_ a pound sign, anyways.
<Smerdyakov>
Why is it wrong because it started as slang?
<Riastradh>
See the last clause of my sentence.
<Xcalibor>
shit, I've got 89 hits of the Swen email worm just today!
<Riastradh>
Swen?
<Xcalibor>
yeah.. the 104kb Microsoft Tech security patch one
<Xcalibor>
it got called Swen...
<Riastradh>
I got 150 of them today, and about 80 of them yesterday.
<Xcalibor>
whoah...
<Riastradh>
A random slang term -- that is _already_ used for a _different_ symbol --, for a symbol that already has a name, doesn't make sense.
<Smerdyakov>
--, isn't even valid morse code.
<Riastradh>
You astound me with your vast knowledge of Morse code, Smerdyakov.
<Xcalibor>
lol
<Riastradh>
And I just got ten more within the past twenty minutes.
<phubuh>
if you guys took the turing test, i don't think you'd win
<Xcalibor>
Smerdyakov: I think Riastradh used the '--' as an elipsis to his text (like using parentheses as I am doig right now)
<Xcalibor>
not even 1 legitimate email in my inbox at the moment, ouch...
<Riastradh>
Xcalibor, he's very aware of how I'm using emdashes, but he didn't agree that it was syntactically correct when he first saw my use of a punctuation mark after one, so he bugs me about it whenever I do it now.
<Xcalibor>
Riastradh: ah... I see... :-)
<phubuh>
I think the comma in the sentence we're talking about is redundant, but otherwise, I agree that punctuation clusters like --; and --, are acceptable
<Riastradh>
phubuh, I was explicitly separating the 'for a symbol that already has a name'.
<Xcalibor>
which comma? I think I missed that particular discussion...
<Xcalibor>
ah, silly me, it is "--,"
<Xcalibor>
I see :-)
<phubuh>
Riastradh, ah, of course. The comma isn't redundant. :-)
<Smerdyakov>
Ugh. ocaml is segfaulting #load'ing .cmo files. :(
<phubuh>
let rec loop () = try
<phubuh>
client#update ();
<phubuh>
loop ()
<phubuh>
with Closed -> ()
<phubuh>
That function isn't as tail recursive as I thought. :(
<Smerdyakov>
Can you move the exception handler to be outside the loop?
<phubuh>
Yeah, I can.
<Xcalibor>
the compiler isn't optimizing that loop?
<Smerdyakov>
Argh... I am rebuilding a library over and over again, and every time I get "File util.cma is not up-to-date with respect to interface Set" when I try to #load it in the repl.
<Smerdyakov>
Does anyone know why that would happen?
<Riastradh>
Do you have a module Set in util.ml?
<Smerdyakov>
Oh. I think I see the problem. This wacky library redefines a module from the standard library.
<Xcalibor>
ugh, ugly thing to do...
buggs|afk has joined #ocaml
buggs has quit [Read error: 60 (Operation timed out)]
foxster has quit [Client Quit]
<phubuh>
in a chain a (); b () gives a the type unit -> 'a; it can properly infer b's. how can i force that a returns unit?
<phubuh>
(the problem is that a is in another module, and ocaml complains about them being incompatible since one has unit -> unit for a, and one has unit -> 'a)
<whee>
phubuh: use the ignore function
<phubuh>
do i have to write a .mli? :/
<phubuh>
oh
<phubuh>
it still doesn't know that a returns unit
<whee>
er, heh
<whee>
it should think a returns unit if you're using it like that
<phubuh>
yeah, i thought so too
<phubuh>
it even gives a warning if it doesn't
<phubuh>
maybe i'm parsing the error wrong
<phubuh>
mind if i paste a type error at about 15 lines? :/
<phubuh>
oh, wait, i heard they invented this thing called the "World Wide Web" on which you can store information
<phubuh>
ah, whee, i figured out a way to "cast" a value to unit:
<phubuh>
let to_unit () = ()
<phubuh>
to_unit value
<phubuh>
:)
<phubuh>
very ugly, but it'll do
<whee>
I think you mean "let to_unit a = ()"
<phubuh>
i don't
<whee>
but then I think that's the definition of ignore
<whee>
your to_unit is unit -> unit
<whee>
heh
<phubuh>
indeed
<phubuh>
what?! the to_unit method works, but only for send_version
<phubuh>
then i wrap update in it, it doesn't make any difference :(
<phubuh>
this is so confusing
<phubuh>
in this piece of code, isn't it REALLY obvious that client#update() is unit->unit?
<phubuh>
let rec loop () = loop (client#update ())
<phubuh>
in try loop ()
<phubuh>
with Closed -> ()
<whee>
err, heh
<phubuh>
UH. now i've got it complaining This expression has type Module.class = < ... > but is here used with type < ... >, where the two ellipsises represent the exact same text
<phubuh>
i feel like i don't grok ocaml's type system when it comes to objects.
<whee>
heh
<Riastradh>
I think OCaml's object system is quite sucky.
<whee>
I think you've got a case of having the same type, but not having the same type :)
<phubuh>
whee, that does sound spot on.
<mattam>
Riastradh: something particularly annoy you ?
<Riastradh>
No first-class classes!
<whee>
ocaml's objects would be more fun with finalizers too
<mattam>
Riastradh: no first class modules either :)
<whee>
unless it has those and I missed it
<whee>
mattam: functors work well enough for that, I guess
<phubuh>
Riastradh, interesting -- that was the real issue behind by rantings about anonymous inner classes
<mattam>
yes, but it's not that flexible
<phubuh>
whee, you can set an initializer to set a Gc finalizer :/