<neiluj>
Is there a way to define a polymorphic function but restrained to types having access to a specific function ? For instance "let print_array ~label a = Printf.eprintf "%s = %s" label ((Array.map (fun e -> (to_string e) ^ "\n") a) |> Array.to_list |> String.concat "")
<neiluj>
where a is an array of elements that can be converted to a string
<neiluj>
sorry it's pretty vague
<neiluj>
maybe adding a module as an argument having to_string in its signature and binding the module's abstract type t to the type of the elements of a?
<neiluj>
if that makes sense
<mclovin>
You could just add a `to_string` parameter to `print_array` ?
<neiluj>
indeed, that's way simpler!
<neiluj>
thanks
kaph has quit [Read error: Connection reset by peer]
Anarchos has quit [Quit: Vision[]: i've been blurred!]
kaph has joined #ocaml
waleee has joined #ocaml
rgrinberg has joined #ocaml
Haudegen has quit [Ping timeout: 248 seconds]
Haudegen has joined #ocaml
spip has quit [Quit: Konversation terminated!]
Anarchos has joined #ocaml
quartz has joined #ocaml
infinity0 has quit [Ping timeout: 260 seconds]
jlrnick has joined #ocaml
tizoc has quit [Quit: Coyote finally caught me]
tizoc has joined #ocaml
<quartz>
Hello. I'm having trouble compiling my code. The error I'm getting is: reference to unbound regexp name 'digit' on line 90 character 3. https://bpa.st/3JYQ
<d_bot>
<NULL> You defined digit as OCaml value and not ocamllex "regexp" (apparently that's how they're called)
<quartz>
What is OCaml value?
<d_bot>
<NULL> A regular OCaml definition
<quartz>
So I need to change line 90 to regexp digit+ as lem...
<quartz>
Ahhh that does not work either
<d_bot>
<NULL> I think your definitions in the preamble won't work, they need to be put in the ocamllex part
<d_bot>
<NULL> I'm talking about digit letter whitespace and newline
<quartz>
Lines 25 - 29?
bartholin has joined #ocaml
<d_bot>
<NULL> Yes
<quartz>
What do you mean by the 'ocamllex part'?
<d_bot>
<NULL> After the closing }
<quartz>
Hmmmm, OK
<quartz>
Now it's telling me: "Error: unbound constructor DEDENT line 30
<d_bot>
<NULL> Not a cheatsheet, but at least it's an exhaustive list
Nahra has quit [Remote host closed the connection]
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Corbin>
In any CAM, including OCaml, is it expected that the bytecode for folding over a list (starting at the nil-end of the list) will push a stack entry for every element in the list?
kaph has quit [Remote host closed the connection]
kaph has joined #ocaml
Anarchos has quit [Quit: Vision[]: i've been blurred!]
dextaa has quit [Ping timeout: 256 seconds]
neiluj has quit [Ping timeout: 260 seconds]
Haudegen has quit [Ping timeout: 272 seconds]
Haudegen has joined #ocaml
<zozozo>
Corbin: assuming that fold_left is tail recursive (which it should), it should operate in constant stack space
neiluj has joined #ocaml
<zozozo>
So if it pushes a stack entry for recursive calls, I'd expect that entry to replace the current one (which might be implemented as a pop then push, but I have no idea if it's a good idea, pour of it's implemented that way in the CAM)
wyrd has quit [Ping timeout: 240 seconds]
quartz has quit [Quit: WeeChat 3.4]
wyrd has joined #ocaml
bartholin has quit [Quit: Leaving]
<Corbin>
zozozo: Curious. Using the labels in https://ocaml.org/api/List.html#1_Iterators, where the list's elements are [b1; b2; ...; bn], how is the list (not) unpacked onto the stack? Wouldn't each of the elements generate a pending stack frame?
<d_bot>
<NULL> (Most of) those functions start from the top, so they follow the pointers and don't have to lay the list down in memory
Haudegen has quit [Ping timeout: 272 seconds]
Haudegen has joined #ocaml
<Corbin>
NULL: That's interesting. Is there documentation on exactly how this works? I've been reading the CAM and ZINC papers, but haven't quite made it all come together.
Haudegen has quit [Ping timeout: 246 seconds]
<d_bot>
<NULL> That's mostly my intuition about how tail-recursion-optimisation works out
neiluj has quit [Quit: Leaving]
<Corbin>
Hm. Still puzzled. A list [b1; b2; ...; bn] would be constructed as (cons bn (cons ... (cons b2 (cons b1 (nil))) ... )). So, in a CAM, if we wanted to deconstruct the list, then the only cell we can access first is bn. Accessing the other cells would require pushing the intermediate cells to the stack, I think?
<d_bot>
<NULL> OCaml lists are prepended, not appended
<Corbin>
Oh! Okay. For some reason I got convinced that ZINC derivatives like OCaml were the other way around in memory. Well, that's one fewer mystery, thanks.
kaph has quit [Read error: Connection reset by peer]