<brianmwaters>
hey i took a quick look at classes and objects in OCaml; i was wondering if it's syntactic sugar for, or implemented as, records of functions that close over a common environment (as one might implement objects in standard ml or scheme)
<brianmwaters>
or is it really a separate language feature?
<troydm>
seperate language feature
<troydm>
implemented to be compatible with functional part
<troydm>
and type system
<brianmwaters>
i guess other parts of the OCaml type system(that i haven't looked at) would explain why it's separate :)
dwmw2 is now known as dwmw2_gone
<troydm>
brianmwaters: it's not seperate
<troydm>
u can use both styles in your code
<brianmwaters>
oh sure, of course
<troydm>
that is why Ocaml is objective/functional programming language
<brianmwaters>
but they're not equivalent if i'm understanding you correctly
<brianmwaters>
equivalent in the sense that conditionals in Standard ML are sugar for pattern matching over booleans
<brianmwaters>
(for example)
travisbrady has quit [Quit: travisbrady]
travisbrady has joined #ocaml
<troydm>
brianmwaters: i'm not sure what you mean by equivalence
<troydm>
syntactic sugar is indeed equivalence
<brianmwaters>
what i mean is "syntactic sugar"
<troydm>
but objective system is not syntactic sugar
<brianmwaters>
alright thanks
<troydm>
it supports polymorpism and multiple inheritence
<troydm>
plus it supports general types
<brianmwaters>
that would make the "record of functions that close over the same environment" somewhat unworkable, then, i guess
<brianmwaters>
so that makes sense
tac has left #ocaml []
chambart has quit [Ping timeout: 246 seconds]
brianmwaters has quit [Quit: Page closed]
travisbrady has quit [Quit: travisbrady]
travisbrady has joined #ocaml
ollehar has quit [Ping timeout: 264 seconds]
madroach has quit [Ping timeout: 248 seconds]
travisbrady has quit [Quit: travisbrady]
madroach has joined #ocaml
<gnuvince>
Once I've installed a library (e.g. re) with OCaml, how do I actually use it?
<gnuvince>
s/OCaml/OPAM/
mattrepl has joined #ocaml
LukeSun has left #ocaml []
leoncamel has quit [Ping timeout: 251 seconds]
olasd has quit [Ping timeout: 276 seconds]
Leonidas has quit [Ping timeout: 245 seconds]
olasd has joined #ocaml
Leonidas has joined #ocaml
mattrepl has quit [Quit: mattrepl]
UncleVasya has joined #ocaml
cdidd has joined #ocaml
cdidd has quit [Read error: Connection reset by peer]
<osa1>
orbitz: the error I'm getting is this: "ocamlyacc: e - the start symbol `one_single_term' has a polymorphic type", any ideas ? the mly file has some lines like this: "%type <'a MlAlgebra.Abstract.expression> one_single_term"
<osa1>
I also tried compiling it with OCaml 3.something but same error
<orbitz>
osa1: gosh no idea. I've never used ocamlyacc
<orbitz>
how old is this library?!
<osa1>
it's from 2000
<orbitz>
which version of ocaml existsed in 2000...
<osa1>
orbitz: actually it's mentioned in the library's website that it requires 2.02 or later, which is obviously false
<orbitz>
hah
<orbitz>
well, that might have been ture at the time :)
<osa1>
maybe I should ask in SO or mailing list or else I will have to read the source and fix it myself
<flux>
ocaml would be in a perfect position to write converters from older language/library version to a newer one, but sadly nobody thinks that's important :)
lexa_ has joined #ocaml
ahokaomaeha has quit [Quit: When I come back, please tell me in what new ways you have decided to be completely wrong.]
mikurubeam has joined #ocaml
<osa1>
can I instantiate a module(not a functor) multiple times in a program ? it looked to me that modules can be usable as classes as in object-oriented programming, am I missing something ?
mikurubeam has quit [Quit: When I come back, please tell me in what new ways you have decided to be completely wrong.]
Cyanure has quit [Remote host closed the connection]
chambart has joined #ocaml
ottbot has joined #ocaml
j2d2j2d2 has quit [Remote host closed the connection]
j2d2j2d2 has joined #ocaml
lexa_ has quit [Ping timeout: 264 seconds]
adotbrown has joined #ocaml
ontologiae has joined #ocaml
Fullma has quit [Quit: Fullma]
Kakadu has joined #ocaml
ontologiae has quit [Ping timeout: 246 seconds]
derek_c has joined #ocaml
<derek_c>
Hello, I want to ask a question about Map.Make
<derek_c>
so I'm doing something like this:
<derek_c>
module M = Map.Make(struct type t = int let compare = compare end)
<derek_c>
according to my understanding, this makes M a map from integer to arbitrary type, right?
<derek_c>
and then I want to do this: type 'a trie = 'a * ('a trie M.t) | Empty
<zorun>
yep
<zorun>
you need a constructor for the first case as well
<derek_c>
oh!!
<zorun>
as in “Data of 'a * ('a trie M.t)”
<derek_c>
damn that's why lol
<derek_c>
thank you so much
<zorun>
you're welcome :)
<derek_c>
zorun: do you know of any decent ocaml IDE?
<derek_c>
what tools do you use for OCaml development?
ttamttam has joined #ocaml
<zorun>
derek_c: tuareg-mode in emacs is pretty standard and works well
<zorun>
otherwise, typerex looks promising, but afaik, it's not packaged in a lot of distro (it's probably easier through pam)
<zorun>
*opam
thomasga has joined #ocaml
Yoric has quit [Ping timeout: 246 seconds]
<derek_c>
excellent, I will try them out. Thank you for help!
mika1 has joined #ocaml
cago has joined #ocaml
hkBst has joined #ocaml
hkBst has quit [Remote host closed the connection]
hkBst has joined #ocaml
hkBst has quit [Changing host]
hkBst has joined #ocaml
mcclurmc has joined #ocaml
osa1 has quit [Ping timeout: 245 seconds]
dwmw2_gone is now known as dwmw2
ontologiae has joined #ocaml
Yoric has joined #ocaml
hkBst has quit [Ping timeout: 246 seconds]
djcoin has joined #ocaml
hkBst has joined #ocaml
derek_c has quit [Ping timeout: 264 seconds]
Yoric has quit [Ping timeout: 256 seconds]
dwmw2 has quit [Quit: Coyote finally caught me]
dwmw2_gone has joined #ocaml
chambart has quit [Ping timeout: 246 seconds]
chambart has joined #ocaml
Icarot has joined #ocaml
Icarot has quit [Client Quit]
lexa_ has joined #ocaml
ontologiae has quit [Read error: Connection reset by peer]
zbroyar has joined #ocaml
ontologiae has joined #ocaml
chattered has joined #ocaml
anderse has joined #ocaml
ttamttam has quit [Remote host closed the connection]
lexa_ has quit [Ping timeout: 264 seconds]
chambart has quit [Ping timeout: 246 seconds]
Icarot has joined #ocaml
troydm has quit [Quit: What is hope? That all of your wishes and all of your dreams come true? (C) Rau Le Creuset]
zbroyar has left #ocaml []
darkf is now known as nagatomajo
Yoric has joined #ocaml
troydm has joined #ocaml
beckerb has joined #ocaml
chambart has joined #ocaml
dwmw2_gone has quit [Quit: Coyote finally caught me]
dwmw2_gone has joined #ocaml
nagatomajo is now known as darkf
_andre has joined #ocaml
djcoin has quit [Quit: WeeChat 0.3.9.2]
adrien_oww has quit [Ping timeout: 276 seconds]
adrien_oww has joined #ocaml
Yoric has quit [Ping timeout: 252 seconds]
Icarot has quit [Ping timeout: 276 seconds]
adrien_oww has quit [Ping timeout: 264 seconds]
adotbrown has quit [Ping timeout: 260 seconds]
dwmw2_gone has quit [Quit: Coyote finally caught me]
chambart has quit [Ping timeout: 272 seconds]
dwmw2_gone has joined #ocaml
adrien_o2w has joined #ocaml
Kakadu has quit [Ping timeout: 264 seconds]
Kakadu_ has joined #ocaml
adotbrown has joined #ocaml
adotbrown has quit [Ping timeout: 276 seconds]
adrien_o2w has quit [Quit: leaving]
adrien_oww has joined #ocaml
yacks has quit [Ping timeout: 264 seconds]
yacks has joined #ocaml
hto_ has joined #ocaml
ben_zen_ has joined #ocaml
tizoc` has joined #ocaml
ollehar has joined #ocaml
tizoc` is now known as tizoc_
tizoc has quit [Disconnected by services]
tizoc_ is now known as tizoc
tizoc has quit [Changing host]
tizoc has joined #ocaml
mikurubeam has quit [*.net *.split]
hto has quit [*.net *.split]
metasyntax has quit [*.net *.split]
ben_zen has quit [*.net *.split]
metasyntax has joined #ocaml
chambart has joined #ocaml
ollehar has quit [Ping timeout: 252 seconds]
Yoric has joined #ocaml
ben_zen_ is now known as ben_zen
dwmw2_gone is now known as dwmw2
hkBst has quit [Remote host closed the connection]
hkBst has joined #ocaml
q66 has joined #ocaml
hkBst has quit [Read error: Connection reset by peer]
ollehar has joined #ocaml
hkBst_ has joined #ocaml
hkBst_ has quit [Changing host]
hkBst_ has joined #ocaml
tane has joined #ocaml
chambart has quit [Ping timeout: 255 seconds]
ollehar1 has joined #ocaml
gnuvince has quit [Ping timeout: 248 seconds]
djcoin has joined #ocaml
Icarot has joined #ocaml
darkf_ has joined #ocaml
adrien_o1w has joined #ocaml
darkf has quit [Ping timeout: 276 seconds]
adrien_oww has quit [Ping timeout: 264 seconds]
thomasga has quit [Ping timeout: 244 seconds]
ollehar has quit [Quit: ollehar]
ollehar1 has quit [Ping timeout: 260 seconds]
ollehar has joined #ocaml
Icarot has quit [Ping timeout: 252 seconds]
thomasga has joined #ocaml
thomasga has quit [Ping timeout: 276 seconds]
mapour has quit [Remote host closed the connection]
thomasga has joined #ocaml
travisbrady has joined #ocaml
gnuvince has joined #ocaml
travisbrady has quit [Client Quit]
thomasga has quit [Ping timeout: 264 seconds]
ttamttam has joined #ocaml
beckerb has quit [Quit: Konversation terminated!]
ttamttam has left #ocaml []
beckerb has joined #ocaml
travisbrady has joined #ocaml
<hcarty>
def-lkb: Any ideas on why querying expression types works but omnicomplete doesn't? I'm happy to put effort into diagnosing the issue but I'm not very familiar with vim + python + ocamlmerlin hacking.
<rks_>
hcarty: what do you mean?
<hcarty>
rks_: I am trying to use merlin on a CentOS 6 system. The system Python is 2.6 so it doesn't work with merlin's vim plugin.
lexa_ has joined #ocaml
<rks_>
def-lkb worked on that yesterday evening
<hcarty>
rks_: I built (using pythonbrew) Python 2.7.3 and vim 7.3 against the updated Python.
<rks_>
It should be working with python>=2.4
<rks_>
(but I don't know if he pushed it on master yet)
mattrepl has joined #ocaml
<rks_>
(it is)
<hcarty>
rks_: Excellent, thanks! I'll update my local copy and see how it goes.
<rks_>
ok :)
mattrepl has quit [Client Quit]
<hcarty>
def-lkb: Thanks for working on a fix
<rks_>
(I don't think the problem you seem to have right now is related to python though)
<rks_>
(but we'll see)
lexa_ has quit [Ping timeout: 255 seconds]
<hcarty>
rks_: Doesn't look like it. I still get the same result (types report, no omnicomplete).
<hcarty>
def-lkb: Thank you for the older python compatibility none the less
<rks_>
ok so hcarty, can you describe a bit more your problem?
<rks_>
(i'm not sure I understood it)
<hcarty>
rks_: Sure. If I open an OCaml source file in vim, I can type "\t" to see the type of the expression under the cursor in normal or visual mode.
<rks_>
yeah sure
<hcarty>
rks_: But, for example, if I type List.<c-x><c-o> I get an error/message saying that there aren't any matches.
<rks_>
oh
<rks_>
I'm guessing that's a problem of path
<hcarty>
rks_: The same configuration works fully on a different Ubuntu 12.04 system. Both are using OCaml 4.00.1 and merlin from opam.
<rks_>
hmmm
<rks_>
just to be sure, can you export MERLIN_LOG=<some_path> before running vim and trying to complete ?
<rks_>
(and paste me the content of that file somewhere)
darkf_ has quit [Quit: Leaving]
<travisbrady>
Anyone have thoughts on what it would take to build something like Storm (http://storm-project.net/) with OCaml?
<hcarty>
rks_: To my untrained eye that looks like a reasonable final "return" value
<rks_>
:D
<rks_>
indeed
<rks_>
so, I have the same log when I try it
<rks_>
... except that it works for me
<rks_>
so you were right the problem is surely on the vim/python side
<rks_>
... but I don't know what could cause the problem, so you will have to wait for def-lkb
<rks_>
sorry
<hcarty>
rks_: It's ok, thanks for the MERLIN_LOG tip!
<hcarty>
That gives me a starting point if I want to dig into this further.
cago has quit [Quit: Leaving.]
<rks_>
:)
travisbrady has quit [Quit: travisbrady]
mika1 has quit [Quit: Leaving.]
<hcarty>
rks_: Do you know how to get some sort of text message from a vim python plugin to the terminal/vim?
travisbrady has joined #ocaml
<hcarty>
rks_: I'm trying to dump data and track where things are being lost but not having much luck.
ollehar1 has joined #ocaml
<hcarty>
rks_: Never mind, it does seem to be working. But something isn't working with omnicomplete because the send_command function isn't being called, or isn't producing the same print output as it does when performing type lookups
<hcarty>
"it" being print statements from python. Not merlin yet, sadly.
<rks_>
hmm
<rks_>
hcarty: seeing the log, the send_command seems to be working
<rks_>
I think the problem appears later, but I don't know where
hkBst_ has quit [Quit: Konversation terminated!]
Kakadu_ has quit []
smondet has joined #ocaml
vext01 has quit [Ping timeout: 264 seconds]
<def-lkb>
hcarty: the current fix is buggy
<def-lkb>
hcarty: some cases don't work anymore… anyway, it's a work around ugly vim design…
<csmrfx>
#vim ;)
mattrepl has joined #ocaml
<def-lkb>
:)
djcoin has quit [Ping timeout: 244 seconds]
travisbrady has quit [Quit: travisbrady]
mattrepl has quit [Read error: Connection reset by peer]
mattrepl has joined #ocaml
mattrepl has quit [Read error: Connection reset by peer]
mattrepl has joined #ocaml
beckerb has quit [Quit: Konversation terminated!]
travisbrady has joined #ocaml
adrien_o1w is now known as adrien_oww
<hcarty>
def-lkb: The problem seems (?) to be in the handoff between vim_complete_cursor and merlin#Complete
<rks_>
(yep)
Kakadu has joined #ocaml
gnuvince has quit [Ping timeout: 260 seconds]
<def-lkb>
hcarty: which version of vim are you using ?
<def-lkb>
hcarty: btw, update master, I fixed a synchronization bug introduced by removing use of py2.7 Counter class
filiformatik has joined #ocaml
filiformatik is now known as belbert
ulfdoz has joined #ocaml
Yoric has quit [Ping timeout: 252 seconds]
ontologiae has quit [Ping timeout: 260 seconds]
pygmalion has joined #ocaml
<pygmalion>
Has anyone had trouble building OCaml 4.xx on CentOS 6? It keeps bombing out at the same point: https://gist.github.com/pygatea/5058501 (using opam btw)
<hcarty>
def-lkb: I've tried with vim 7.2 and 7.3
tautologico has joined #ocaml
chattered has quit [Ping timeout: 272 seconds]
<tautologico>
why my ocaml installation in linux does not have the graphics module? I installed through ocamlbrew (with opam included)
anderse has quit [Quit: anderse]
<hcarty>
pygmalion: I was able to build OCaml 4.00.1 and a few the patched versions of 4.00.1 on CentOS 6 (64bit) through oapam
<hcarty>
opam
<hcarty>
tautologico: The OCaml configuration script was probably unable to find the relevant X headers. I don't remember which headers it needs, but I've had trouble with that before.
<hcarty>
def-lkb: Updated master via :BundleInstall!, same result under 7.2 and 7.3
djcoin has joined #ocaml
<pygmalion>
hcarty: What prereqs did you install? I'm starting from a fresh CentOS 6 (64 bit), doing "yum install make gcc" and then using the opam bootstrapping installer (http://opam.ocamlpro.com/doc/Quick_Install.html) and failing with those errors every time.
<pygmalion>
hcarty: by every time I mean with various different patched versions
<hcarty>
pygmalion: I don't remember which packages were installed. This install is shared by several people and has a lot of development RPMs installed.
<hcarty>
pygmalion: I'm not sure what the a minimal set would be
<hcarty>
s/the a/the/
<pygmalion>
hcarty: Fair enough, thanks.
<pygmalion>
hcarty: At least it's good to know that it *should* work.
<tautologico>
hcarty: yeah, it's probably that, I think I know how to solve it… any way to recompile via ocamlbrew or do I have to install everything again?
gnuvince has joined #ocaml
<hcarty>
tautologico: Sadly no. If you are using an opam-managed compiler then it can do that.
<tautologico>
how do I use opam to manage the ocaml compilers?
<tautologico>
basic usage only says how to install packages and so on
<tautologico>
the page on advanced usage has stuff about ocaml compilers
<hcarty>
tautologico: Ah, sorry about that
<tautologico>
np
<hcarty>
thelema: It may enrage gasche to discuss this here before moving to the mailing list, but for what it's worth I like your proposal. It is simple and should cover basic functionality.
<hcarty>
thelema: What would this mean for the default/pervasive Enum functions and operators? Would then stick around or be replaced by something else?
<thelema>
hcarty: I have to give credit to Yaron; it was his idea, which I (at the time) immediately rejected as impossible, but have since realized that stripping away length and clone make it simple and elegant
<thelema>
hcarty: they would stick around, and be implemented on top of this infrastructure
<thelema>
err, you're referring to Enum.map being included in Batteries.Pervasives?
<hcarty>
thelema: Yes
<companion_cube>
hi thelema
<thelema>
ah. Until batteries 3.0, they're sticking around, and I see plenty of life left in the 2.x series
<thelema>
companion_cube: hi. Sorry for the agressive response to your pull request
<companion_cube>
that's ok :D
<companion_cube>
my pull request was quite premature, I was a bit tired after spending 2 hours tracking a type error
<companion_cube>
but the discussion it entailed is quite interesting
<companion_cube>
is gasche on irc?
<thelema>
companion_cube: no
<companion_cube>
hmm, we should try to forward the thread to the ocaml ML, but I don't really know how...
<thelema>
not the ocaml ml, the batteries ml
<companion_cube>
maybe
<thelema>
which I've already done, in a way. hcarty was just responding to my post
<companion_cube>
although it looks like the Enum type and the likes are a pervasive problem
<thelema>
Agreed, here's my solution... (digging up link to batteries post)
<thelema>
companion_cube: while I like your idea of inverting the flow of control(('a -> unit) -> unit), I think (unit -> 'a) is more natural, and easier to get accepted, despite its need for an exception.
<companion_cube>
it's more natural, but in fact it makes it harder to define Sequence/Enum on a container
<companion_cube>
because you need to store "where you are in the container" somewhere
<companion_cube>
and update it when next() gets called
<companion_cube>
whereas Sequence only requires a way to iterate, and lowers the risks for a structure to be modified during an iteration
<thelema>
true, but it allows easier partial iteration
<companion_cube>
indeed :)
<thelema>
and partial consumption is a very common pattern
<thelema>
sequence hides the state inside a closure, as opposed to making it explicit
<companion_cube>
well, Sequence.take is a form of partial consumption
<thelema>
quite inefficient for many uses
yroeht has quit [Quit: WeeChat 0.3.7]
<thelema>
also, it doesn't allow the large data structure conversion.
yroeht has joined #ocaml
<companion_cube>
no no, the implementation of Sequence.take does not require storage ;)
<thelema>
which is the biggest reason for enum; given a list that takes up 3/4 of RAM, conversion to a set that takes up a little less than that can't be done without crazy swapping using sequence
<companion_cube>
it's like iter, but interrupted after [n] elements
<thelema>
whereas it can be done using Enum
<companion_cube>
oh, I see
<thelema>
with enum, the list can be GC'ed as it's consumed
<companion_cube>
because you consume the list while you build the set?
<thelema>
exactly
<companion_cube>
maybe having both Stream and Sequence would cover most usages
<companion_cube>
stream for the kind of usage you were talking about (which I admit I did not think of)
<thelema>
Stream is very similar to the (unit -> 'a), but it bakes in a bunch of other generators that I'm not happy having
<thelema>
Enum's advantage over stream is for another very specific thing: cloning, which makes sense for RNG streams and makes repeat consumption efficient in some other cases
<companion_cube>
RNG?
<thelema>
random number generator
<companion_cube>
oh, ok
<thelema>
actually, PRNG
<flux>
thelema, did you see that BSD-licensed sequence library for ocaml?
<companion_cube>
:D
<thelema>
flux: the one that companion_cube wrote?
<flux>
thelema, yes, probably. is that what the discussion is about?-)
<flux>
companion_cube, but you didn't use the benchmark module! which looks great :)
<companion_cube>
yes :s
yacks has quit [Read error: Connection reset by peer]
<thelema>
flux: I keep meaning to add code from my bench module to benchmark... I think bench looks better, even if it doesn't give the crosstab comparison
<flux>
well, benchmark was a bit difficult to use at first. if you give it a very fast function, it seem to benchmark it for ages.
<thelema>
yes, bench does a better job of auto-calibrating measurements to the speed of your function
<companion_cube>
thelema: about the (interesting) problem of transforming a 3/4-of-ram list into a set, I think it would be possible with Sequence, with care, if one has a "iter_consume : 'a Sequence.t -> (('a -> unit) -> unit)"
<companion_cube>
such that if you get such an iterator, and lose all references to the sequence, then it allows to iterate on the elements once
<thelema>
companion_cube: tricky to lose references to the sequence
<companion_cube>
well, the iterator does not need to refer to the sequence
<companion_cube>
only to the underlying list
<companion_cube>
(if it's a list)
<companion_cube>
hmm, I see the problem in the general case
pkrnj has joined #ocaml
<thelema>
mutability is basically required, because recursion (even tail recursion) keeps things in scope
<companion_cube>
if I read the List.iter function, by itself, it does not keep the head of the list in scope, right?
<companion_cube>
the problem is that Sequence would store the head of the list to be able to iterate on it again
<thelema>
yes, because it's not destructive like enum/stream
ottbot has quit [Ping timeout: 255 seconds]
<companion_cube>
so a way of converting a Sequence to a destructive Sequence would be useful
<thelema>
but I don't think you can do this
<thelema>
for exactly the reason that take is like it is.
<thelema>
take and drop
<companion_cube>
(assuming the sequence itself goes out of scope)
mcsquiggedy has quit [Ping timeout: 276 seconds]
<thelema>
you can't lose scope of the sequence itself
<thelema>
at least not without making a copy of the whole thing
ollehar1 has quit [Ping timeout: 252 seconds]
<companion_cube>
hmm, right, there will probably be a pointer to the container somewhere on the stack...
<companion_cube>
another thing that lacks is combine
derek_c has joined #ocaml
<thelema>
combining two sequences into a sequence of pairs?
<thelema>
yes, I'm not sure how you'd do that
<companion_cube>
I can't :)
<companion_cube>
unless one of the sequences if forced
<companion_cube>
otoh split : ('a * 'b) sequence -> 'a sequence * 'b sequence is doable
<thelema>
because your consumption pattern fits .iter
<companion_cube>
exactly
<djcoin>
é
<djcoin>
oups
<companion_cube>
that's why I say that Sequence is less versatile than Enum; but I think that, with the same quality of implementation, they should be faster
tautologico has quit [Quit: tautologico]
<companion_cube>
maybe it should just be based on fold rather than iter, but anyway
<companion_cube>
thelema: do you think a one-time sequence would be useful? A proper ('a -> unit) -> unit, that does not keep a reference on the beginning of the iterated list (for instance)
pygmalion has quit [Ping timeout: 256 seconds]
zbroyar has joined #ocaml
ulfdoz has quit [Ping timeout: 255 seconds]
gnuvince has quit [Ping timeout: 255 seconds]
<thelema>
yes, although hmm...
<thelema>
The locus of control being inside the sequence is somewhat restrictive
<ollehar>
any used the ocaml mysql lib? i'm having troubles with charset, åäö dissapears, when saving into database.
<thelema>
possibly a mysql normalization issue? iirc, it does things like this unless you ask it nicely not to
<Leonidas>
I am trying to use the FFI and have trouble specifying a pointer
<thelema>
pointers can be treated directly as ocaml values
<Leonidas>
I have a C function which takes a pointer and updates it periodically. So I thought that I could just use a ref
<adrien>
opaque pointers
<adrien>
Leonidas: definitely not :-)
<thelema>
nope, just make a new type name
<adrien>
Leonidas: a ref is an ocaml struct with a mutable field named "contents"
<Leonidas>
yes, I thought that I can just extract the address of the field and pass it to the function
<Leonidas>
which would allow me to read the value via !myref from ocaml
<thelema>
is the value an int?
<Leonidas>
but while reading the value and writing it works perfectly with the Field(v, 0) macro used as rvalue and rvalue, I am completely unable to get the address out of it
<Leonidas>
thelema: yes it is.
<thelema>
if so, then in your C function, you can take the int ref and use Field(v,0)
<thelema>
&Field(v,0)
<Leonidas>
well, it is a size_t which should be the same thing
<thelema>
size_t != ocaml int because of the low bit
<Leonidas>
what to do then?
<thelema>
you'll have to use the Val_int and Int_val macros to convert back and forth
<thelema>
also, can't really be unsigned in the OCaml world
<Leonidas>
thelema: yes that would work, but I don't control the code which writes to the size_t
<Leonidas>
I do this: archive_write_open_memory(a, b, s, size_t);
<thelema>
then I'd recommend having a boxed size_t somewhere and provide ocaml accessor functions to get/set its value
<Leonidas>
the last parameter is what I want to specify as ref
<Leonidas>
hmm, yeah, probably the best. and use it as an opaque value
<thelema>
it won't be as simple as !myref, but it'll work
<Leonidas>
thelema: so I just set size_t* outUsed = (size_t*)v; ?
ccasin has quit [Ping timeout: 252 seconds]
<thelema>
yes, like that. don't forget to heap allocate the v on the C side
<thelema>
I guess you might be able to get away with allocating it on the OCaml side too, as the pointer will be passed in to your accessor function
<Leonidas>
mallocing a single int?
<thelema>
yes.
ccasin has joined #ocaml
<thelema>
yes, better to do it on the C side, otherwise it can move.
<Leonidas>
wait, how to do that on the ocaml side? I'd prefer that
<Leonidas>
the printf returns 42 and when I Printf.printf it returns 42
<pippijn>
that's odd.. change it back to Val_int
<pippijn>
what version of ocaml are you using?
<Leonidas>
hmm, with Val_int I get 42 now too
<Leonidas>
how the heck did I get 21 before?
<pippijn>
then you had a problem with the build system
<pippijn>
or something
jpdeplaix has joined #ocaml
<Leonidas>
quite possible. I started cleaning it before every build because I had an even stranger problem before
<pippijn>
because you effectively changed nothing, and now it works
<pippijn>
anyway, it works now
<Leonidas>
yep. What does not work is that libarchive does not set any values on that pointer
<Leonidas>
or rather: it sets it to zero
<Leonidas>
but that's not an ocaml problem
<Leonidas>
more like pebkac or something
mattrepl has quit [Quit: mattrepl]
<pippijn>
ok
ivan\ has quit [Quit: ERC Version 5.3 (IRC client for Emacs)]
<pippijn>
when you're done with it, you should probably put that pointer into a custom block
<companion_cube>
I'd like value types in ocaml...
<pippijn>
and free it when the custom block is collected
ivan\ has joined #ocaml
<Leonidas>
pippijn: yes, possibly. Although I am not completely sold on custom blocks
<pippijn>
that will be another indirection, making things slower, though
<Leonidas>
I use them, but I am not really sure whether I use them correctly.
<pippijn>
oh
<pippijn>
you don't like them?
<Leonidas>
well I do, but the point is that libarchive sometimes gives me objects that I am not supposed to free myself
<pippijn>
then you don't use custom blocks for those
<pippijn>
those objects sound dangerous
<pippijn>
you don't want to give those to users of your binding
<pippijn>
at least not alone
<Leonidas>
yeah, so probably I'll switch these back to normal opaque pointers and this out_used pointer to a custom block
<Leonidas>
yeah, I don't plan to export these at all.
<pippijn>
good
<pippijn>
as long as you control them, it's fine
<Leonidas>
the concept is not that bad actually, the rule is: if you created it via foo_new() you need to foo_free() them yourself, otherwise the library free()s them for you
<Leonidas>
nice for C programmers, less nice for bindings
<pippijn>
the concept is bad, if it doesn't define *when* the library frees them
<Leonidas>
it frees them when I close the archive
<pippijn>
yes
<Leonidas>
actually, it reminds me of the Python-C-API which is similar
<pippijn>
so anytime you operate on such an object in ocaml, you need to make sure an archive pointer is in scope
<Leonidas>
yes, exactly
<pippijn>
the archive pointer must always outlive those object pointers
<pippijn>
as long as you guarantee that, you're good
<Leonidas>
should be fine
<pippijn>
what's wrong with debian's ocaml? still at 3.12 :(
<adrien>
freeze
<pippijn>
adrien: sid froze?
<Leonidas>
testing froze
<pippijn>
so why is sid waiting?
<pippijn>
it's been in experimental for months
<adrien>
heh, no, but I can imagine they didn't spend time on that
<Leonidas>
sounds likely
LukeSun has joined #ocaml
Kakadu has quit []
mikurubeam is now known as ahokaomaeha
hto_ has quit [Ping timeout: 276 seconds]
pygmalion has joined #ocaml
<pippijn>
and lazy ubuntu just uses debian's packages, so they also wait
pygmalion has quit [Ping timeout: 276 seconds]
ottbot has quit [Ping timeout: 244 seconds]
ollehar1 has joined #ocaml
<mehdid>
for ocaml, ubuntu is not lazy... but inexistent
troydm has quit [Read error: Operation timed out]
<mehdid>
and yes, it has been in experimental for months and no one had time to rebuild packages and put them on ocaml.debian.net
<mehdid>
so for now, debian ocaml maintainers are just waiting for the freeze to finish... so that they can ask a slot for the 4.0 transition
<mehdid>
but if there are volunteers willing to do some work, I can show the right contact points :)
adotbrown has joined #ocaml
ulfdoz has quit [Ping timeout: 240 seconds]
Cyanure has joined #ocaml
mattrepl has joined #ocaml
djcoin has quit [Quit: WeeChat 0.3.9.2]
Cyanure has quit [Remote host closed the connection]
pygmalion has joined #ocaml
oriba has joined #ocaml
travisbrady has quit [Quit: travisbrady]
ollehar has quit [Quit: ollehar]
troydm has joined #ocaml
Yoric has quit [Ping timeout: 252 seconds]
<companion_cube>
thelema: I'm taking a look at BatConcurrent, out of curiosity, and I see "compose". Do you think that having a total ordering on locks, so you always compose them in increasing order, would prevent some deadlocks?