<companion_cube>
what is it supposed to do? It's not very clear from the names :)
<caseyjames>
sorry it gathers up values matching a predicate into intervals a list of tuplets (start index, start value, end index, end value)
<Drup>
caseyjames: as a side note, post your gist as .ml, not .txt. colors are good :]
<companion_cube>
caseyjames: so it should return [[60, 62]; [50, 52]; [78, 80]] ?
<caseyjames>
[(0, 60, 2, 62); (3, 50, 6, 80)]
<companion_cube>
ah, it doesn't count decreasing intervals, ok
<companion_cube>
that's the kind of function I would document if I were you ;)
<companion_cube>
(for instance in the .mli if you wrote one)
<caseyjames>
I definitely will. I'm worried the coding is bad... the (0,0,0,0) and other repeated elements... also the lingering suspicions that there is some sort of List.fold that knocks this down to a line
<companion_cube>
caseyjames: if you're worried about readability, I would suggest you write a record type for itnervals
<companion_cube>
type 'a interval = { first_idx : int; first : 'a; last_idx : int; last: 'a; }
<Drup>
caseyjames: it's probably some sort of fold, yes, but it will not really help for readability
<companion_cube>
it is indeed a fold_left, where the accumulator is a bit complicated
<caseyjames>
I was thinking of doing it with records, but hadn't tried record update. I will transfer the code over once I test it a bit more. I'm cracking into OUnit tomorrow
<companion_cube>
also, if you need to access elements by index very often, an array may be better than a list. But I can't judge from this snippet
boogie has joined #ocaml
<caseyjames>
Do you have any experience with ocamlgraph?
<pippijn>
I just used it once
<pippijn>
for graphviz stuff
<pippijn>
it's quite slow, so I didn't use it for actual work
Guest96193 has quit [Remote host closed the connection]
<pippijn>
it's cute though, with functors everywhere
<caseyjames>
Slow compared to BGL?
<pippijn>
I don't know BGL
weie has joined #ocaml
<pippijn>
I implemented my own graphs with arrays or bitsets where appropriate
<caseyjames>
Ahh
<companion_cube>
pippijn: is it really this slow?
<caseyjames>
yes, i've been eyeballing the whole matrix approach... is that what bitsets are?
<companion_cube>
I'd think the imperative implementation would be fast
<pippijn>
companion_cube: the imperative implementation uses hashtables
<companion_cube>
yes, so it should be quite fast
<pippijn>
it's all very generic
<pippijn>
it's "quite" fast
<companion_cube>
but you can probably roll out an implementation for integers, based on bitsets
Drup has quit [Ping timeout: 260 seconds]
<pippijn>
but at least an order of magnitude slower than the custom one
<companion_cube>
that might be problems of inlining :(
<pippijn>
companion_cube: the arrays are direct indexing with hashconsed objects
<pippijn>
companion_cube: there is no hashing involved
<companion_cube>
ah, so you have more information
<pippijn>
yes
<companion_cube>
but I still believe you could use ocamlgraph with a custom graph implementation
<pippijn>
each object has a unique small integer identifier
<companion_cube>
or even contribute a special graph implementation for hashconsed objects ^^
<pippijn>
maybe
<pippijn>
I might do it someday
<pippijn>
the graph parts are no longer relevant to the performance, anyway
<pippijn>
they used to be much slower, but I optimised other parts, so now the graphs may be implemented with the more elegant ocamlgraph abstraction
boogie has quit [Ping timeout: 245 seconds]
<caseyjames>
I'm trying to wrap my head around how I would work an algorithm like this into a graph. If I were to have a edge from both parent to child and vice versa for every element contained in each interval, would I run it after the fact as a separate process?
<companion_cube>
sorry, got to go to lunch
<pippijn>
companion_cube: actually I quite like my array graphs, because they are immutable after initialisation
<pippijn>
so I produce graphs on construction, and after that change their access modifier to immutable and can be sure they won't be modified
<caseyjames>
is that just an adjacency matrix?
<companion_cube>
I too have some matrix graph somewhere, to implement completion of partial orderings...
<pippijn>
caseyjames: I have an adjacency matrix, as well
<ggole>
...same
<ggole>
Keyed by integers, implying objects have to either map to or include one
<pippijn>
right
<ggole>
In theory that's less general: in practice, doesn't matter.
<ggole>
(Or didn't for me.)
<pippijn>
I have a finite and unchanging set of elements
<pippijn>
so I can simply number them
<pippijn>
the indices are private ints
<caseyjames>
Do you then just have a suite of your own graph traversal tools and algorithms?
<pippijn>
caseyjames: I don't need those
<pippijn>
I just needed a graph, no tools
<ggole>
Yeah, same. Just is_adjacent and iter_adjacent.
<pippijn>
right
<ggole>
And the obvious accessors.
* ggole
time for food
<caseyjames>
Its 3:24 am here sleep beacons. Thanks for the perspective
Yoric has joined #ocaml
ollehar has quit [Ping timeout: 248 seconds]
zzz_ has quit [Remote host closed the connection]
<mrvn>
caseyjames: perfect time for a snack
zzz_ has joined #ocaml
ocp has quit [Quit: Leaving.]
Drup has joined #ocaml
caseyjames has quit [Ping timeout: 250 seconds]
Drup has quit [Ping timeout: 245 seconds]
kizzx2 has quit [Quit: Leaving.]
Neros has joined #ocaml
ben_zen has joined #ocaml
Drup has joined #ocaml
boogie has joined #ocaml
Neros has quit [Ping timeout: 260 seconds]
boogie has quit [Ping timeout: 260 seconds]
_andre has joined #ocaml
jayprich has joined #ocaml
Neros has joined #ocaml
Transhumanist has quit [Ping timeout: 248 seconds]
ben_zen has quit [Ping timeout: 248 seconds]
ollehar has joined #ocaml
ygrek_ has quit [Remote host closed the connection]
ygrek_ has joined #ocaml
Neros has quit [Ping timeout: 245 seconds]
boogie has joined #ocaml
boogie has quit [Ping timeout: 245 seconds]
ben_zen has joined #ocaml
ygrek_ has quit [Ping timeout: 246 seconds]
ben_zen has quit [Quit: leaving]
Simn has quit [*.net *.split]
tizoc has quit [*.net *.split]
ivan\ has quit [*.net *.split]
Cypi has quit [*.net *.split]
Khady has quit [*.net *.split]
reynir has quit [*.net *.split]
adrien has quit [*.net *.split]
mal`` has quit [*.net *.split]
Nahra has quit [*.net *.split]
orbitz has quit [*.net *.split]
gildor has quit [*.net *.split]
ski has quit [*.net *.split]
orbitz has joined #ocaml
ski has joined #ocaml
adrien has joined #ocaml
Cypi has joined #ocaml
tizoc has joined #ocaml
gildor has joined #ocaml
tizoc has quit [Changing host]
tizoc has joined #ocaml
Simn has joined #ocaml
ivan\ has joined #ocaml
Nahra has joined #ocaml
reynir has joined #ocaml
ivan\ has quit [Changing host]
ivan\ has joined #ocaml
mal`` has joined #ocaml
Nahra has quit [Changing host]
Nahra has joined #ocaml
reynir has quit [Changing host]
reynir has joined #ocaml
Khady has joined #ocaml
jayprich has quit [Ping timeout: 245 seconds]
mika1 has joined #ocaml
UncleVasya has joined #ocaml
boogie has joined #ocaml
boogie has quit [Ping timeout: 252 seconds]
rwmjones has quit [Ping timeout: 248 seconds]
ygrek_ has joined #ocaml
zpe has joined #ocaml
zpe has quit [Remote host closed the connection]
_andre has quit [Ping timeout: 260 seconds]
_andre has joined #ocaml
talzeus has joined #ocaml
rwmjones has joined #ocaml
<ggole>
Am I missing something to print a substring?
<ggole>
Yes I am.
bondar has joined #ocaml
ygrek_ has quit [Remote host closed the connection]
ygrek_ has joined #ocaml
<mrvn>
String.sub?
boogie has joined #ocaml
<ggole>
That's a bit wasteful, isn't it? Anyway, Pervasives.output was what I wanted.
<ggole>
(Missed it since there's no 'print' in the name.)
boogie has quit [Ping timeout: 248 seconds]
jayprich has joined #ocaml
cdidd has quit [Read error: Connection reset by peer]
zpe has joined #ocaml
zpe has quit [Ping timeout: 252 seconds]
Yoric has quit [Ping timeout: 245 seconds]
mika1 has quit [Quit: Leaving.]
cdidd has joined #ocaml
ygrek_ has quit [Remote host closed the connection]
ygrek_ has joined #ocaml
boogie has joined #ocaml
shinnya has joined #ocaml
boogie has quit [Ping timeout: 246 seconds]
talzeus has quit [Remote host closed the connection]
<ollehar>
is there a shorthand notation for `string_of_int 12`?
<ollehar>
like 12str
<ollehar>
hm
<Simn>
"12"
<ollehar>
no, `string_of_int var`
<ollehar>
:)
<adrien_oww>
let f = string_of_int in
<adrien_oww>
f 12
<adrien_oww>
no? :P
<ggole>
Python refugee?
rwmjones has quit [Ping timeout: 248 seconds]
UncleVasya has quit [Quit: UncleVasya]
<ollehar>
ggole: me? no.
<ollehar>
only sick of writing string_of_int thousand times a day
<ollehar>
let (&) = string_of_int ?
<adrien_oww>
you can
<adrien_oww>
or List.rev_map
ttamttam has quit [Quit: ttamttam]
<companion_cube>
ollehar: you may use Printf
<ggole>
If you're always writing that in the toplevel, maybe put let str = string_of_int in .ocamlinit
<ggole>
If not... suck it up, string_of_int is nice and readable.
<ggole>
(IMHO.)
ttamttam has joined #ocaml
morolin has quit [Ping timeout: 264 seconds]
ttamttam has quit [Client Quit]
<ollehar>
one could make a syntax extension, like
<ollehar>
^i str = ^ string_of_int str
<Drup>
ollehar: you can do prefix operator starting by ! or ~
<companion_cube>
ollehar: do you use it to print ints ?
<adrien_oww>
you could try haskell
<adrien_oww>
there's an operator for everything
<companion_cube>
stop being sarcastic, adrien :)
<adrien_oww>
well, I'm sure there's one to do int -> string
<adrien_oww>
(well, it might be 'a -> string actually so that wouldn't be bad)
<Drup>
ollehar: but tbh, it's not better than just "soi" as an alias ...
<ollehar>
Drup: nice
<ollehar>
yeah, guess you're right
<companion_cube>
adrien_oww: there's a typeclass 'a -> string, yes
<adrien_oww>
companion_cube: we only need to ask hnrgrgr a bit more :D
* companion_cube
seldom needs string_of_int, because of {f,s,}printf
<Drup>
adrien_oww: s/ask/whip/
<Drup>
:]
rwmjones has joined #ocaml
<adrien_oww>
Drup: let's ask nicely first :)
<ollehar>
companion_cube: yeah, print = Print.sprintf could work nicely... thanks for the tips!
<adrien_oww>
I often do "let sp = Printf.sprintf"
<companion_cube>
ollehar: it's really useful if you want to wrap the string_of_int in a context, like an error message
<companion_cube>
this way it's just sprintf "%d is a bad integer" i
ontologiae has quit [Ping timeout: 248 seconds]
snearch has joined #ocaml
snearch has quit [Read error: Connection reset by peer]
<adrien_oww>
reynir: I'm interested in changing /topic
<adrien_oww>
the bit.ly link points to it
<adrien_oww>
but the sympa archives are often down
<adrien_oww>
plus, if I could, I'd skip the url-shortener step
boogie has joined #ocaml
ontologiae has joined #ocaml
<reynir>
adrien_oww: I guess I can host it on my website if you prefer that
<adrien_oww>
I can do it too but that should be on ocaml.org
nikki93 has joined #ocaml
Drup has quit [Ping timeout: 240 seconds]
nikki93 has quit [Remote host closed the connection]
ollehar has joined #ocaml
ontologiae has quit [Quit: WeeChat 0.4.0]
djcoin has quit [Quit: WeeChat 0.4.1]
ygrek_ has quit [Ping timeout: 260 seconds]
nikki93 has joined #ocaml
boogie has quit [Remote host closed the connection]
cantstanya has joined #ocaml
jbrown has quit [Ping timeout: 268 seconds]
Anarchos has joined #ocaml
wmeyer has quit [Remote host closed the connection]
boogie has joined #ocaml
<technomancy>
any Async pros around? I need to make an Async call inside a callback whose API I don't control, so I need to turn it into a blocking call.
<technomancy>
what I'd like to do is just "park" the thread until a given Ivar gets filled
<technomancy>
I can't just bind to a Deferred since I need the callback to return the value I get from the async call
yacks has joined #ocaml
<mrvn>
so make a Deferred that sets a condition and then wait for it.
<technomancy>
sure; not seeing how that's done in the docs
<technomancy>
specifically the "wait for it" part =)
<mrvn>
technomancy: see the Condition module in the docs
<technomancy>
mrvn: thanks; looks promising
<technomancy>
this looks a bit like a promise; is that a decent analogy?
<mrvn>
In your case you could also just use a mutex. Lock it before the async code, unlock it Deferred in the async call and lock it again. The second lock will block till the defereed runs.
mika1 has joined #ocaml
<technomancy>
I think a Condition is better because it conveys a value
<technomancy>
feels like I'd need a side-channel with a mutex
<mrvn>
you mean for the return value of the async call?
<technomancy>
right
<mrvn>
makes total sense. you would need a ref otherwise.
nikki93 has quit [Remote host closed the connection]
Drup has joined #ocaml
zpe has quit [Remote host closed the connection]
<technomancy>
so... once I get my value, I Condition.signal c value
<technomancy>
but in my consumer I do Condition.wait c |> Deferred.peek and get None every time
<technomancy>
even if I hard-code my signal value to a known string
<mrvn>
but it blocks?
* technomancy
inserts a sleep to tell
<technomancy>
ok, so it doesn't actually block. hrm.
<mrvn>
well, I guess you are doing something wrong
<technomancy>
I agree =)
<technomancy>
shouldn't Deferred.peek (Condition.wait c) never return None?
darkf has joined #ocaml
<orbitz>
how come?
jayprich has quit [Quit: jayprich]
<technomancy>
my understanding is that wait would never return until the deferred is filled
<technomancy>
but obviously my understanding is flawed somehow
<orbitz>
No, wait returns a defered
<technomancy>
so... it doesn't wait?
<orbitz>
No, how could it?
<mrvn>
wait should wait till the condition is signaled. With what you signal it is your problem.
<orbitz>
Condition.wait c >>= Deferred.peek (* should never return None *)
<technomancy>
by parking the thread?
<orbitz>
technomancy: why would you want to park a thraed i nASync?
<technomancy>
orbitz: because I have to work with an API that isn't async
<mrvn>
orbitz: scrollback. it's in a callback that isn't async
<orbitz>
Sure, but that is disticnt from calling Deferred.peek on somethin, why would you call Deferred.* in the code running in a thread somewhere?
<technomancy>
would be nice to have more than 3 lines of docs on Condition =\
<orbitz>
Dodesn't Async have a "run in thread and give me back the deferred" function?
<orbitz>
and you run some blocking thing with In_thread.run, and that thing you call has to call back to something in Async again, is that correct or not?
<technomancy>
right; except my blocking thing is an ffi call, not In_thread.run
<orbitz>
you're calling a blocking thing from Async without running it through a thread?
<mrvn>
technomancy: you haven't said why you need to do the network stuff async
<orbitz>
the Async scheduler will be stuck in that case so how do you expect that to owrk?
<technomancy>
orbitz: I assume you can yield to the scheduler
<orbitz>
technomancy: this doesn't sound likea good idea
<mrvn>
technomancy: unless it is multithreaded
<orbitz>
technomancy: ocaml-core mailing list or caml-list are probably good place to ask. I don't know how to solve your program, I suspect you'll at least need to run your blocking call in a thread first
<technomancy>
unfortunately I don't really control the execution context =\
<orbitz>
which execution context?
<mrvn>
technomancy: you haven't said why you need to do the network stuff async
<technomancy>
orbitz: the foreign readline call
<technomancy>
well... maybe I can drop the whole thing in a thread
<orbitz>
technomancy: i'm not saying you should, i'm saying doing a blocking ffi not In_thread.run is a bad idea in async, since it will block the entire async
<orbitz>
which is what In_thread.run does for you...
<technomancy>
so there's no way to manually yield then
<technomancy>
mrvn: started using it just because it's mostly well-documented
<mrvn>
technomancy: what would yield give you? That doesn't tell the scheduler when to wake you up again
<orbitz>
technomancy: How hard is it to write a coroutine in C without an ocaml ffi in there...
<technomancy>
mrvn: I was assuming that's what Condition.wait did
<orbitz>
no, it just waits
<orbitz>
and blocks
<technomancy>
orbitz: I'd have to actually learn C for that
Yoric has joined #ocaml
<technomancy>
part of the point of OCaml is to avoid that =)
<orbitz>
technomancy: I'm not telling you to do taht
<technomancy>
(for me anyway)
<mrvn>
technomancy: just do the network stuff sync and the problem goes away.
<orbitz>
i'm giving you an idea why "can't i just yield" is really ahrd
<technomancy>
orbitz: ah, gotcha
<technomancy>
my only other experience with a non-concurrent runtime is elisp, which lets you yield to other async processes pretty easily, but I understand the context is very different
yezariaely has quit [Quit: Leaving.]
<orbitz>
you're in C code which is quite idfferent
nisstyre has joined #ocaml
<technomancy>
mrvn: async is a really good fit for the rest of this program though
<orbitz>
what doe sthe callback you want to pass actually do?
<technomancy>
I'm writing a fast-launching repl client for lumbering clojure programs
<technomancy>
~500 lines so far
<orbitz>
technomancy: I'm sure you can do waht you want in some way, I'm sure it's scarey. And I'm also sure I have no ide ahow
<technomancy>
doing this without async would mean either keeping two sockets open or wrapping the regular socket in async-ness
<orbitz>
or just making a new socket ofr each connection
<orbitz>
readline is humantime afterall...
<technomancy>
hm; yeah... the scope of what I'd need to support just completion messages is much reduced from the full protocol support
<technomancy>
I could look into just implementing a tiny slice of the protocol
<technomancy>
still need to figure out how to construct a null-terminated string array for readline though, which sounds like even crazier magick
Yoric has quit [Ping timeout: 245 seconds]
nikki93 has joined #ocaml
<orbitz>
Well, the way I implement protocols is a pure parsing part, and then yo ucan toss any sync/async layr on top
<orbitz>
technomancy: doesn't ocaml-ctypes handle all that for you?
<technomancy>
orbitz: it supports a pretty limited set of array operations
<orbitz>
ok
<technomancy>
I think it only works with arrays where you pass the array and the size as separate args
<technomancy>
which you can't do if you need to return an array
<orbitz>
isn't taht what ptr_opt gives you in ocaml-ctypes?
nikki93 has quit [Remote host closed the connection]
<orbitz>
None -> NULL?
<technomancy>
yeah, but I need an array of strings, not string options
<technomancy>
so it needs to be non-homogeneous afaict
<orbitz>
ptr_opt isn't a string option AFAIK
pozzy has quit [Quit: Page closed]
<pippijn>
(non-homogenous = heterogenous)
<technomancy>
heh; right
<orbitz>
"Construct a pointer type from an existing type (called the reference type). This behaves like Ctypes.ptr, except that null pointers appear in OCaml as None"
<technomancy>
huh; maybe that would work then
<orbitz>
i think it's the point of the construct :)