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/
brettgilio has quit [Ping timeout: 252 seconds]
John_Ivan has joined #ocaml
olle has quit [Ping timeout: 265 seconds]
<discocaml> <ilo Kali> :ocaml:
uics has quit [Remote host closed the connection]
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 252 seconds]
troydm has quit [Ping timeout: 268 seconds]
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 268 seconds]
azimut has joined #ocaml
Haudegen has quit [Ping timeout: 268 seconds]
xgqt has quit [Quit: WeeChat 3.6]
John_Ivan has quit [Ping timeout: 248 seconds]
chrisz has quit [Ping timeout: 268 seconds]
chrisz has joined #ocaml
ohperitel has quit [Quit: ZNC 1.8.2 - https://znc.in]
ohperitel has joined #ocaml
chrisz has quit [Ping timeout: 260 seconds]
jao has quit [Ping timeout: 260 seconds]
chrisz has joined #ocaml
motherfsck has quit [Quit: quit]
jao has joined #ocaml
terrorjack has quit [Quit: The Lounge - https://thelounge.chat]
tomku has quit [Read error: Connection reset by peer]
tomku has joined #ocaml
terrorjack has joined #ocaml
<discocaml> <MasterBuilder> is there any way to express to the compiler that a match arm is unreachable? specifically when a list will never be empty
<discocaml> <MasterBuilder> so handling `[]` is unnecessary
xd1le has joined #ocaml
<discocaml> <MasterBuilder> can always throw an unthrowable exception I guess which has the benefit that if those invariants are violated after all it will be visible, but it's still a bit of an eyesore, in this case there is absolutely no doubt, what I want is a "list of length >= 1" type but I don't really want to go creating one of those
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 248 seconds]
jao has quit [Ping timeout: 252 seconds]
<discocaml> <hopefullyhat> What is the reason for the list never being empty?
<discocaml> <MasterBuilder> the reason is a little complicated, I'm open to the notion of it being poorly designed, anyway I have a list of events that I loop over but before the iteration can start I first need to wait for one event to arrive, which must be handled immediately and then it is saved because the information is still needed even though it won't be handled again, so I wait for one event, then I start the iteration by calling a recursive function with a
<discocaml> <hopefullyhat> If the list is indeed non-empty, you might want to use a non-empty list type
<discocaml> <MasterBuilder> and even if I were to set a flag to indicate it's been handled to avoid it being handled again in the recursive call (if no other events are available), it's still dumb because the invariant is quickly established after that, so it's just noise
<discocaml> <MasterBuilder> is there an easy way to do it and using entirely the same list API?
<discocaml> <hopefullyhat> Don’t think so 😦
<discocaml> <MasterBuilder> yeah that does bother me a little
<discocaml> <hopefullyhat> Unless you want to write your own type or use an existing library, the neatest is just failwith “Impossible” in the branch
<discocaml> <MasterBuilder> yeah that's what I have now
<discocaml> <MasterBuilder> I'll think about using a better type, I did find a library that offers such a type but it didn't look very good
<discocaml> <MasterBuilder> and stackoverflow suggested some complicated GADT that I don't really understand so much
<discocaml> <MasterBuilder> well, thanks
keyboard has quit [Ping timeout: 260 seconds]
<discocaml> <ilo Kali> Maybe a silly idea, but perhaps you could use a text editor to copy the List module's signature and edit all occurrences of `'typevar list` to `('typevar,'phantom) list` (or whatever you want to use to store the relevant type information), then paste it back and restrict the List module (or a copy) to it
infinity0 has quit [Ping timeout: 252 seconds]
<discocaml> <leviroth> There is core_kernel.nonempty_list, but maybe that’s the library you had already seen. I’ve used it; I find it really convenient sometimes, but other times missing a function or being unable to prove something necessary to the compiler can be annoying.
<discocaml> <MasterBuilder> Hmm no haven't seen that, I don't think, honestly didn't look very hard, is that part of Base?
<discocaml> <MasterBuilder> To be honest I don't need the full power of List for this one, kinda depends on a few things that are a bit unclear at the moment, possibly don't need anything at all, so maybe whipping up a custom type wouldn't be terrible, I'm a bit skeptical of pulling in a massive library just for that
<discocaml> <MasterBuilder> is that the only nonempty list you're aware of?
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 252 seconds]
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 248 seconds]
czy has joined #ocaml
czy has left #ocaml [ERC 5.4 (IRC client for GNU Emacs 28.2)]
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 260 seconds]
nd__ has joined #ocaml
bartholin has joined #ocaml
Tuplanolla has joined #ocaml
keyboard has joined #ocaml
<discocaml> <psychokitty> I don't suppose there's a cooperative way to build OCaml objects from C that uses exported information about the decided object layout for types?
azimut_ has joined #ocaml
azimut has quit [Remote host closed the connection]
<discocaml> <psychokitty> I know there's specific functions for common things, `caml_alloc_some`, etc. but I see that a lot of bindings basically have to know the object layout of the things they wish to construct, and sort of hardcode the construction themselves (the LLVM bindings, for example; https://github.com/llvm/llvm-project/blob/main/llvm/bindings/ocaml/llvm/llvm_ocaml.c#L1578-L1597).
keyboard has quit [Ping timeout: 248 seconds]
keyboard has joined #ocaml
uics has joined #ocaml
mro has joined #ocaml
<discocaml> <emillon> That's how the majority of bindings are written, yes
Anarchos has joined #ocaml
<discocaml> <emillon> You can have a look at the ctypes library which uses a different approach (with no C but a Ocaml api to manipulate C values)
mro has quit [Remote host closed the connection]
<Anarchos> how to get the ocaml/ocaml 4.14 branch from github on my own github repo ?
mro has joined #ocaml
waleee has joined #ocaml
olle has joined #ocaml
keyboard has quit [Ping timeout: 260 seconds]
noonien has quit [Quit: The Lounge - https://thelounge.chat]
noonien has joined #ocaml
mro has quit [Remote host closed the connection]
<Anarchos> why do the compiler recompiles checkstack.c each time a launch make world ?
Haudegen has joined #ocaml
uics has quit [Remote host closed the connection]
uics has joined #ocaml
wingsorc__ has quit [Remote host closed the connection]
mechap has joined #ocaml
Serpent7776 has joined #ocaml
gwizon_ has quit [Remote host closed the connection]
mro has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
uics has quit [Remote host closed the connection]
nd__ has quit [Ping timeout: 252 seconds]
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 248 seconds]
nd__ has joined #ocaml
wingsorc has joined #ocaml
nd__ has quit [Ping timeout: 260 seconds]
bgs has joined #ocaml
mro has quit [Remote host closed the connection]
<discocaml> <leviroth> @MasterBuilder it's not a part of base, but it depends on base, so if you're trying to keep dependencies really light it might not work for you.
mro has joined #ocaml
<discocaml> <leviroth> You could also potentially just copy the type definition from that library; you may or may not need any of the helper functions it contains.
nd__ has joined #ocaml
<discocaml> <leviroth> Actually it depends on core, lol
nd__ has quit [Ping timeout: 252 seconds]
<discocaml> <MasterBuilder> yeah that could work
John_Ivan has joined #ocaml
nd__ has joined #ocaml
<discocaml> <MasterBuilder> but if core is only an indirect dependency that's not necessarily so bad, I'm already using stuff from Containers which is why I'm hesitant to directly pull in another library extension, that sounds like a big mess
nd__ has quit [Ping timeout: 265 seconds]
nd__ has joined #ocaml
uics has joined #ocaml
<discocaml> <leviroth> You’d take the extra dependency for binary size etc, but you should be able to use it without having to open Core or anything like that.
nd__ has quit [Ping timeout: 268 seconds]
nd__ has joined #ocaml
<discocaml> <MasterBuilder> you know it was actually much easier to create this type than I thought
<discocaml> <MasterBuilder> just
<discocaml> <MasterBuilder>
<discocaml> <MasterBuilder> ```ocaml
<discocaml> <MasterBuilder> module NonEmptyList = struct
<discocaml> <MasterBuilder> type 'a t = ( :: ) of 'a * 'a list
<discocaml> <MasterBuilder> end
<discocaml> <MasterBuilder> ```
<discocaml> <MasterBuilder>
<discocaml> <MasterBuilder> then I locally open this module and didn't even need to change the code at all, so for pure lists this works great, as long as I don't use any List functions this is adequate
<discocaml> <MasterBuilder> maybe I'll look into using the `non_empty_list` module if I need more power
<discocaml> <MasterBuilder> but this is fine for now
nd__ has quit [Ping timeout: 255 seconds]
chrisz has quit [Ping timeout: 252 seconds]
<discocaml> <NULL> You can also replicate all List functions you may want to use in a `List` submodule, so that it still works cleanly
chrisz has joined #ocaml
<discocaml> <MasterBuilder> oh that's a good point
uics has quit [Remote host closed the connection]
jao has joined #ocaml
infinity0 has joined #ocaml
bartholin has quit [Remote host closed the connection]
bartholin has joined #ocaml
bartholin has quit [Client Quit]
mro has quit [Remote host closed the connection]
count3rmeasure has joined #ocaml
mro has joined #ocaml
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 260 seconds]
bartholin has joined #ocaml
mro has quit [Remote host closed the connection]
count3rmeasure has quit [Ping timeout: 268 seconds]
mro has joined #ocaml
<discocaml> <froyo> `type 'a nonempty = 'a * 'a list`
<discocaml> <froyo> `let cons x (y, ys) = x, y :: ys`
<discocaml> <froyo> `let hd (h, _) = h`
<discocaml> <froyo> `let tl (_, t) = t`
<discocaml> <froyo> `let to_list (h, t) = h :: t`
<discocaml> <froyo> etc etc
Stumpfenstiel has joined #ocaml
mechap_ has joined #ocaml
<discocaml> <NULL> `type 'a non_empty_list = (::) of 'a * 'a list` is better because you will be able to write `[0; 1]` and it will be a valid non-empty list
mechap_ has quit [Client Quit]
<discocaml> <NULL> Also, you can have `let to_list : 'a non_empty_list -> 'a list = Obj.magic`
nd__ has joined #ocaml
mechap has quit [Ping timeout: 248 seconds]
nd__ has quit [Ping timeout: 268 seconds]
<discocaml> <octachron> Using `Obj.magic` to avoid a single allocation in `let to_list (x::y) : _ list = x :: y ` is overkill.
<discocaml> <MasterBuilder> I want to be able to pattern match the head and tail as if it were a normal list, that's the whole point
<discocaml> <geoff> If the first item is guaranteed and you don't want to have the impossible branch, why not unroll one step and get/process the first element before entering the function that matches on a list
<discocaml> <NULL> The first part is definitely the most reasonable argument
uics has joined #ocaml
waleee has quit [Ping timeout: 248 seconds]
John_Ivan_ has joined #ocaml
John_Ivan has quit [Ping timeout: 252 seconds]
keyboard has joined #ocaml
<discocaml> <geoff> wait I read the above stuff wrong ignore me 😅
<discocaml> <geoff> I feel like redesigning to not have to pass in a dummy list with one element that you don't want to actually reprocess is the answer, but I could be reading the description of the problem wrong. I'd say it's unlikely a new type is required though
<discocaml> <MasterBuilder> I do still need it but just as static info, but you're totally right it was the entirely wrong abstraction, I just made it another parameter instead of having it as the head of the list, actually, it used to be an `option` parameter because the way the code was written necessitated that at the time (wasn't unrolled as you say), but I hated that because that can also never be `None` so it's the wrong type, so I just decided to put it at
olle has quit [Ping timeout: 260 seconds]
count3rmeasure has joined #ocaml
mro has quit [Remote host closed the connection]
random-jellyfish has joined #ocaml
mro has joined #ocaml
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 246 seconds]
olle has joined #ocaml
uics has quit [Remote host closed the connection]
azimut_ has quit [Ping timeout: 255 seconds]
jlrnick has joined #ocaml
xd1le has quit [Quit: xd1le]
uics has joined #ocaml
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 260 seconds]
mro has quit [Remote host closed the connection]
mro has joined #ocaml
John_Ivan__ has joined #ocaml
John_Ivan_ has quit [Ping timeout: 256 seconds]
Anarchos has quit [Quit: Vision[]: i've been blurred!]
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 260 seconds]
count3rmeasure has quit [Quit: Leaving]
<discocaml> <geoff> Another parameter, or having the list function be local and closing over it is what I had in mind yea. That's what I've done in similar situations
nd__ has joined #ocaml
olle has quit [Ping timeout: 260 seconds]
nd__ has quit [Ping timeout: 252 seconds]
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 252 seconds]
bartholin has quit [Quit: Leaving]
nd__ has joined #ocaml
John_Ivan has joined #ocaml
nd__ has quit [Ping timeout: 268 seconds]
John_Ivan__ has quit [Ping timeout: 260 seconds]
Anarchos has joined #ocaml
jlrnick has quit [Ping timeout: 248 seconds]
nd__ has joined #ocaml
nd__ has quit [Ping timeout: 252 seconds]
kotrcka has joined #ocaml
keyboard has quit [Ping timeout: 260 seconds]
uics has quit [Remote host closed the connection]
Tuplanolla has quit [Quit: Leaving.]
szkl has joined #ocaml
uics has joined #ocaml
mro has quit [Remote host closed the connection]
random-jellyfish has quit [Quit: Client closed]
Serpent7776 has quit [Ping timeout: 248 seconds]
uics has left #ocaml [#ocaml]
<discocaml> <MasterBuilder> oh yeah I actually could do that too by shuffling some code around, the function already is local
<discocaml> <MasterBuilder> Hmm but actually since it's changing it would have to be a reference and that just makes it ugly