companion_cube changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 4.14.0 released: https://ocaml.org/releases/4.14.0.html | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
<companion_cube> Haha no
<companion_cube> There is no such thing as an uninitialized array
<companion_cube> (alas; it makes it hard to write dynamic arrays)
<discocaml> <mbacarella> i mean, i don't mind if accessing the uninitialized array causes a segfault
<discocaml> <mbacarella> i just don't want to pay to initialize an array when i create it
<discocaml> <mbacarella> i mean, i don't mind if reading the uninitialized array causes a segfault
alexherbo2 has quit [Remote host closed the connection]
<discocaml> <mbacarella> perhaps i should just turn everything into a float :/
alexherbo2 has joined #ocaml
<discocaml> <geoff> The cope that is being used in the vector PR on the stdlib (the last time I read it) is an array of option.
<discocaml> <geoff> Depending on what you are doing, maybe that would be acceptable (though still sad)
<discocaml> <Anurag> @pilothole maybe https://github.com/janestreet/base/blob/master/src/option_array.mli can work for your usecase.
<discocaml> <mbacarella> ```ocaml
<discocaml> <mbacarella> (** [unsafe_get_some_assuming_some t i] is unsafe both because it does not bounds check
<discocaml> <mbacarella> [i] and because it does not check whether the value at index [i] is none or some,
<discocaml> <mbacarella> assuming that it is some. *)
<discocaml> <mbacarella> val unsafe_get_some_assuming_some : 'a t -> int -> 'a
<discocaml> <mbacarella> ```
<discocaml> <mbacarella> aww yeah
<discocaml> <MasterBuilder> what an ugly name for a function 🥲
<discocaml> <mbacarella> it should be `val dangerous_get`
<discocaml> <NULL> That would still initialise the array
Anarchos has quit [Quit: Vision[]: i've been blurred!]
<discocaml> <NULL> You're filling it up with zeros, irrespective of the type
<discocaml> <NULL> (In Base's case, not zeros but a fixed random value
<discocaml> <NULL> (In Base's case, not zeros but a fixed random value)
<discocaml> <geoff> `Caml.Obj.magic `x6e8ee3478e1d7449` in particular
<discocaml> <mbacarella> oh, indeed.
<discocaml> <NULL> In containers it is zeros (`Obj.repr ()` to be precise)
<discocaml> <MasterBuilder> what are you doing that you can't afford to zero init the array anyway?
<discocaml> <mbacarella> so what I'm hearing is if I write some C stub to create an array but don't initialize it I'm fine so long as I fully initialize it before the array is collected
<discocaml> <NULL> If you go this route, the GC should never read uninitialised cells. I can't tell you how often the GC reads cells or what cells it reads however
<companion_cube> It's unpredictable
<companion_cube> But if it can reach the array it'll eventually traverse it all
<discocaml> <mbacarella> seems like perhaps I can copy/paste this and give my own initial values https://github.com/ocaml/ocaml/blob/trunk/runtime/array.c#L201
<discocaml> <mbacarella> (caml_make_vect is Array.create)
tsns has quit [Remote host closed the connection]
tsns has joined #ocaml
tsns has quit [Remote host closed the connection]
tsns has joined #ocaml
<discocaml> <MasterBuilder> portmidi bindings look ok
<discocaml> <mbacarella> they even work on macos with modern DJ controllers
<discocaml> <MasterBuilder> you've used it?
<discocaml> <mbacarella> once or twice https://github.com/mbacarella/portmidi 😛
<discocaml> <MasterBuilder> oh wait you made them?
<discocaml> <mbacarella> the bindings
<discocaml> <mbacarella> yeah
<discocaml> <MasterBuilder> oh, nice haha
tsns has quit [Remote host closed the connection]
<discocaml> <mbacarella> re: array stuff, basically I'm trying to initialize an Array from a list. but I know the size of the list already which I'd like to give to Array.of_list, which unfortunately needs to scan the list once to get the length. additionally, it initializes the whole array to whatever the list hd was, then updates it from the tl
<discocaml> <mbacarella> would be nice if there was a fast `Array.of_list_take ~n lst` or something
<discocaml> <geoff> `init` also initializes the array to `(f 0)`. You could use it, or your own function doing similar though to avoid iterating the list more than once
<discocaml> <geoff> `init` also initializes the array to `(f 0)`. You could use it, or your own function doing similar though to avoid iterating the list more than once though
<discocaml> <geoff> woops forgot about editing and IRC 😬
<discocaml> <MasterBuilder> pretty much everything looks weird on the IRC side, can't see quotes and the edits are just multiple messages, not ideal :/
<discocaml> <MasterBuilder> pretty much everything looks weird on the IRC side, can't see quotes and the edits are just multiple (mostly duplicated) messages, not ideal :/
<discocaml> <MasterBuilder> whoops, I also did it without thinking -_-
<discocaml> <mbacarella> Oh hmm I suppose I could use a ref to the list and then in the Array.init f take the list ref hd as the value and replace update the ref with the tl
<discocaml> <mbacarella> Oh hmm I suppose I could use a ref to the list and then in the Array.init f take the list ref hd as the value and update the ref with the tl
<discocaml> <mbacarella> I couldn't even let myself think of this because it's so ugly
<discocaml> <geoff> your own function where you use create then recurse over the list would be better and cleaner
<discocaml> <geoff> `List.iteri` even
<discocaml> <mbacarella> I'm presuming the Array.init lets me skip the cost of creating with a dummy initializer though
<discocaml> <mbacarella> But perhaps the 3 ref operations per init f will wipe that gain out
<discocaml> <mbacarella> argh denied
<discocaml> <mbacarella> I'm going to be doing like a trillion graph traversals so I'm trying to shave millis off of the basic traverse op
<discocaml> <geoff> I think that `List.iteri` or your own `let rec` on the list is the best that you can do given that you can't avoid filling the array when it's created
<discocaml> <mbacarella> without writing C stubs...
<discocaml> <peval> i've needed the same for my HAMT implementation for a long time, tons of pointless initialization and copying
<discocaml> <peval> and list buffers with Array.of_list because there's no mutable array buffers
<discocaml> <peval> time to write some C
<discocaml> <mbacarella> yeah god help me I think I need to write some C
alexherbo2 has quit [Remote host closed the connection]
<discocaml> <geoff> Using a vector (even if it isn't builtin) isn't a possibility?
alexherbo2 has joined #ocaml
<discocaml> <geoff> (instead of list, since you are writing to an array in the end anyway)
<discocaml> <mbacarella> I've actually never come across an OCaml vector lib. What's good?
<discocaml> <geoff> I've never used one of them, but I'm sure that @companion_cube is partial to the one in containers
<discocaml> <mbacarella> well I do like c-cube
<companion_cube> I'm definitely the opposite of partial on that one :)
<companion_cube> The opposite of impartial
<companion_cube> Double negations, man
<discocaml> <geoff> 😂 🤔
xenu has joined #ocaml
<discocaml> <geoff> the boxed version is similar to what exists outside of the stdlib already though iirc
<companion_cube> I'm a bit sad that we're probably going to have a boxed version
<companion_cube> It's really not as useful...
oriba has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
Tuplanolla has quit [Quit: Leaving.]
<companion_cube> The bridge kind of sucks but I'm still glad it's there
<discocaml> <geoff> More lively than without
<discocaml> <geoff> Is it not the same bot library that came with cats?
<companion_cube> It's just matterbridge
chrisz has quit [Ping timeout: 246 seconds]
chrisz has joined #ocaml
motherfsck has quit [Ping timeout: 260 seconds]
motherfsck has joined #ocaml
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rgrinberg has joined #ocaml
motherfsck has quit [Ping timeout: 252 seconds]
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<discocaml> <peval> got about 5% faster for making big trees out of arrays by adding elements (functionally) with a c stub instead of ocaml versions
rgrinberg has joined #ocaml
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rgrinberg has joined #ocaml
bartholin has joined #ocaml
bartholin has quit [Quit: Leaving]
motherfsck has joined #ocaml
waleee has quit [Ping timeout: 255 seconds]
jao has quit [Ping timeout: 246 seconds]
bgs has joined #ocaml
motherfsck has quit [Ping timeout: 252 seconds]
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
motherfsck has joined #ocaml
Haudegen has joined #ocaml
bgs has quit [Remote host closed the connection]
Serpent7776 has joined #ocaml
szkl has joined #ocaml
azimut has quit [Ping timeout: 255 seconds]
olle has joined #ocaml
<discocaml> <froyo> i worry that putting on ocaml heap scannable memory filled with garbage is just racing the gc not to crash and burn. possibility of random segfaults just to save a couple nanos. would there be a possibility actually?
<discocaml> <froyo> mbacarella: You mentioned that you want array of list where the list's length is known. is `Array.make len (List.hd xs)` followed by `List.iteri (Array.unsafe_set arr) xs` really that bad?
rwmjones has quit [Ping timeout: 252 seconds]
rwmjones has joined #ocaml
<discocaml> <peval> the gc wont run during the c stubs. it's the same as all the other stdlib array functions and small enough to be confident it works tbh.
<discocaml> <peval> in my case like a persistent vector you need obj.magic even if you do it in ocaml
<discocaml> <peval> it doesn't get you a lot though because c calls are slow and the compiler can't see through them so it probably isn't worth it in most cases
<discocaml> <froyo> did you publish your persistent vector impl btw? I was planning to write a library myself, so I might just not, lol
<discocaml> <peval> but it's pretty common to write some sort of combinatorial solver in ocaml and have my scheme or haskell version be 10x faster simply because the extra overhead of the data structures in ocaml
<discocaml> <froyo> I can see c stubs being a win if you still initialize your data but use SIMD intrinsics to do so
<discocaml> <froyo> i wonder if there's something specific to them that makes that not a valid thing to do though
<discocaml> <froyo> otoh memset is probably already sped up with simd.. doesn't ocaml use that internally
<discocaml> <peval> i don't see much downside to specializing the exact stdlib stubs for something like ```Array.append a [| x |]``` to get ```Array.push a x``` even if it's only a small gain
<discocaml> <peval> it goes through a pretty convoluted path for simple things
<discocaml> <froyo> oh speaking of arrays, it looks like Leo closed his (unboxed) array types PR. what's up with that?
<discocaml> <froyo> it was one of the things i looked forward to the most, i hope the design isn't retired
<discocaml> <peval> anything like that will probably pass through here first to be worked out now, i'd guess https://github.com/ocaml-flambda/ocaml-jst/pulls
<discocaml> <octachron> @hyphen Leo's opinion has been that unboxed types should be a prerequisite of this PR for few years now. It doesn't really make sense to keep a PR open when the RFCs for an eventual prerequisite PR is still a work in progress.
<discocaml> <froyo> That's fair
bgs has joined #ocaml
darchitect has quit [Quit: WeeChat 3.7.1]
spip has joined #ocaml
bobo has quit [Ping timeout: 260 seconds]
bgs has quit [Remote host closed the connection]
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #ocaml
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #ocaml
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #ocaml
<discocaml> <Emile Trotignon> The main issue with this is the GC. You could probably do this with a C bindings or maybe even bytes, but then the GC would not look at what is inside, and if you put ocaml values other than ints in it they might get freed (or moved).
<discocaml> <Emile Trotignon> You could also probably do some unsafe shenanigans to change the tags so that the GC does look inside, but then your uninitialised memory could be old freed ocaml values that would cause trouble when the GC tries to scan.
<discocaml> <Emile Trotignon> If you do not need to store ocaml values, but just int or chars, then a C bindings would definitely work.
<discocaml> <Emile Trotignon> Maybe `Bigarray` has some stuff in it for you as well, I am not sure
Haudegen has quit [Quit: Bin weg.]
<discocaml> <Emile Trotignon> Maybe you could actually do what you want with a C stub, because I believe the GC does not run while C code is executed, but you would have to really sure that this is the case.
bgs has joined #ocaml
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #ocaml
jao has joined #ocaml
<discocaml> <Et7f3 (@me on reply)> Can we resisze array from c side ? Like add value then realloc
Haudegen has joined #ocaml
<discocaml> <Emile Trotignon> yeah I guess, but editing ocaml values like a savage will have consequences on the GC side. I was talking about initialiasing with a known length, not resizing per se
<discocaml> <Emile Trotignon> More efficient List.to_array, not Dynarray basically
motherfsck has quit [Ping timeout: 246 seconds]
azimut has joined #ocaml
azimut has quit [Remote host closed the connection]
azimut has joined #ocaml
duckie has joined #ocaml
motherfsck has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
rgrinberg has joined #ocaml
perrierjouet has quit [Quit: WeeChat 3.8]
perrierjouet has joined #ocaml
<discocaml> <Nemo159> Hello everyone, am new to the community and actively looking forward to contribute to this community, can someone please help me where to start with
count3rmeasure has joined #ocaml
Haudegen has joined #ocaml
tsns has joined #ocaml
Serpent7776 has quit [Quit: leaving]
wingsorc has quit [Remote host closed the connection]
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
count3rmeasure has quit [Ping timeout: 260 seconds]
count3rmeasure has joined #ocaml
tsns has quit [Remote host closed the connection]
count3rmeasure has quit [Ping timeout: 248 seconds]
count3rmeasure has joined #ocaml
trev has joined #ocaml
<discocaml> <Et7f3 (@me on reply)> Welcome 🤗 what subject interest you ? What kind of contribution you are seeking ? Have you a working compiler ready to fire ?
mro has joined #ocaml
trev has quit [Remote host closed the connection]
rgrinberg has joined #ocaml
mro has quit [Remote host closed the connection]
rgrinberg has quit [Client Quit]
mro has joined #ocaml
tsns has joined #ocaml
count3rmeasure has quit [Read error: Connection reset by peer]
Anarchos has joined #ocaml
Tuplanolla has joined #ocaml
mro has quit [Remote host closed the connection]
waleee has joined #ocaml
mro has joined #ocaml
mro has quit [Read error: Connection reset by peer]
mro has joined #ocaml
<Anarchos> is it possible to reuse the C header parser from compcert in another ocaml program ?
bartholin has joined #ocaml
wingsorc has joined #ocaml
<Anarchos> how to install lwt.unix through opam ?
<companion_cube> opam install lwt
<companion_cube> (if you have base-unix; if you don't, you're screwed anyway)
<Anarchos> i have base.unix
<Anarchos> \o/
cedric has joined #ocaml
Anarchos has quit [Quit: Vision[]: i've been blurred!]
Anarchos has joined #ocaml
alexherbo2 has quit [Remote host closed the connection]
bgs has quit [Remote host closed the connection]
alexherbo2 has joined #ocaml
tsns has quit [Remote host closed the connection]
tsns has joined #ocaml
<discocaml> <Et7f3 (@me on reply)> > C header parser from compcert in another ocaml program
<discocaml> <Et7f3 (@me on reply)> I don't think licence allow it
xgqt has quit [Remote host closed the connection]
xgqt has joined #ocaml
<Anarchos> ok
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #ocaml
<Anarchos> companion_cube dune needs lwt to compile, and vice-versa
tsns has quit [Remote host closed the connection]
cedric has quit [Quit: Konversation terminated!]
cedric has joined #ocaml
troydm has quit [Ping timeout: 252 seconds]
cedric has quit [Client Quit]
fcambus has joined #ocaml
<discocaml> <Anurag> Dune doesn’t require lwt to compile.
mro has quit [Quit: Leaving...]
bartholin has quit [Quit: Leaving]
<Anarchos> anurag /_boot/dune.exe build @install File "otherlibs/dune-rpc-lwt/src/dune", line 4, characters 38-46: 4 | (libraries result csexp dune_rpc lwt lwt.unix unix) ^^^^^^^^ Error: Library "lwt.unix" not found.
azimut has quit [Ping timeout: 255 seconds]
azimut_ has joined #ocaml
Anarchos has quit [Quit: Vision[]: i've been blurred!]
manicennui has joined #ocaml
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #ocaml
bobo has joined #ocaml
spip has quit [Ping timeout: 252 seconds]
Haudegen has quit [Ping timeout: 252 seconds]
proportions has joined #ocaml