Leonidas changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 5.1.1 released: https://ocaml.org/releases/5.1.1 | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
oriba has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
<discocaml> <Ada> yucky
CuriousErnestBro has joined #ocaml
<CuriousErnestBro> hi
mima has quit [Ping timeout: 268 seconds]
CuriousErnestBro has left #ocaml [Textual IRC Client: www.textualapp.com]
waleee has quit [Ping timeout: 240 seconds]
fweht has joined #ocaml
rgrinberg has joined #ocaml
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
rgrinberg has joined #ocaml
azimut has quit [Ping timeout: 255 seconds]
Serpent7776 has joined #ocaml
<dh`> it's difficult to avoid global state in lex/yacc-style lexers and parsers
<dh`> actually I guess it's mostly lex-style lexers
Serpent7776 has quit [Ping timeout: 240 seconds]
mima has joined #ocaml
Serpent7776 has joined #ocaml
bartholin has joined #ocaml
raphaal has joined #ocaml
<raphaal> hi all
<raphaal> I have and issue with Str package - I try to build C main program with ocaml as secondary language, I use ocamlopt
<raphaal> I use Str library, the regexp in particular
bartholin has quit [Quit: Leaving]
mima has quit [Ping timeout: 264 seconds]
<raphaal> The build command is: ocamlfind $(OCAMLOPT) -output-obj -o $@ $< -linkall -linkpkg -package str
<raphaal> But the linker reports undefined reference to `re_string_match', and similar regexp related functions
<raphaal> the required functions are defined in .opam/5.0.0/lib/ocaml/stublibs/dllcamlstr.so
<raphaal> what I need to change in the build command to link this automatically?
gentauro has joined #ocaml
<raphaal> oh, I changed -output-obj to -output-complete-obj
<raphaal> and I removed linking against libasmrun
<raphaal> and It worked
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
azimut has joined #ocaml
mima has joined #ocaml
mima has quit [Ping timeout: 268 seconds]
waleee has joined #ocaml
darchitect has joined #ocaml
<darchitect> hey guys I have got a pretty basic question, but chatgpt is giving me a disturbingly stupid answer
<darchitect> I have these types:
<darchitect> type address =
<darchitect> { name : string
<darchitect> ; address : string
<darchitect> ; years_lived : int
<darchitect> }
<darchitect> type web_address =
<darchitect> { name : string
<darchitect> ; address : string
<darchitect> ; years_hosted : int
<darchitect> }
<darchitect> type address_book =
<darchitect> | PhysicalAddressBook of address list
<darchitect> | WebAddressBook of web_address list
<darchitect> my question is -> how do I pattern match the `name` of the first entry of the address list in a match expression?
<darchitect> My initial thinking was something like this:
<darchitect> let print_first = function
<darchitect> | PhysicalAddressBook ab ->
<darchitect> (match ab with
<darchitect> | [] -> failwith "empty address book!"
<darchitect> | {name; _; _} :: _ -> name)
<discocaml> <Kali> the issue here is that you only need one wildcard for records
<discocaml> <Kali> since records are not positional, you just need {name; _}
<discocaml> <Kali> you don't need a wildcard for each element
<discocaml> <Kali> just one for all not matched on
boozec has joined #ocaml
<darchitect> oh brilliant !
<darchitect> it makes perfect sense
<darchitect> is there a cleaner way to match this without needing the inner match btw ?
<discocaml> <Kali> not really, unless you consider
<discocaml> <Kali> | r::_ -> r.name
<discocaml> <Kali> to be cleaner
<octachron> You can inline the second match in the first. `PhysicalAddressBook ({name;_} :: _ ) ->`. Not sure if I would call that cleaner.
<darchitect> yeah it's not really cleaner since I have to handle the empty list case as well
<darchitect> but thanks anyway !
<darchitect> thinks are starting to click
<discocaml> <_ggole> You can nest the matches directly, like `| PhysicalAddressBook ({name; _}::_) -> name`
<discocaml> <pigeon.v> companion_cube: you could wrap the parser inside a functor, or am I missing something?
neiluj has joined #ocaml
mro has joined #ocaml
mro has quit [Ping timeout: 260 seconds]
mro has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
szkl has quit [Quit: Connection closed for inactivity]
<discocaml> <Ada> raphaal i would avoid using Str in general
<raphaal> why?
<raphaal> and what I should use instead?
mro has quit [Ping timeout: 268 seconds]
<discocaml> <Ada> it uses global state, the performance is pretty bad and it only supports a small non standard subset of regex
<discocaml> <Ada> i like re, does full perl style regexes , there are a few other options as well
<dinosaure> raphaal: ocaml-re can be a solution if you want to use regex
<dinosaure> str is not actively maintained
<discocaml> <Ada> it’s a separate library nowadays so it’s only really kept around for compatibility
<raphaal> thanks, I'll check it
<raphaal> maybe stupid question, is there a doc for the Re?
<discocaml> <._null._> ocaml.org/p/re (you can replace re with any package)
<raphaal> thanks, not the best, but it's better than reading source or tests directly
torretto has joined #ocaml
alexherbo2 has joined #ocaml
<companion_cube> @pigeon.v hu, not a bad idea with a generateive functor
mro has joined #ocaml
waleee has quit [Quit: updating stuff]
boozec has quit [Ping timeout: 264 seconds]
mro has quit [Ping timeout: 260 seconds]
boozec has joined #ocaml
noddy has quit [Quit: WeeChat 4.1.1]
noddy has joined #ocaml
torretto has quit [Quit: WeeChat 4.1.1]
mro has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
mro has quit [Remote host closed the connection]
boozec has quit [Ping timeout: 260 seconds]
azimut has quit [Ping timeout: 255 seconds]
famubu has quit [Quit: leaving]
neiluj has quit [Remote host closed the connection]
boozec has joined #ocaml
dreadedfrog has joined #ocaml
boozec has quit [Ping timeout: 240 seconds]
dreadedfrog has quit [Remote host closed the connection]
<darchitect> hey guys
<darchitect> I've got 2 .ml files in lib/ using dune. I want to import a type and it's constructors from one of the files to the other so that i don't get unbound module exception. What is the best way to do this ?
<darchitect> example -> I need to import Leaf, Node (type 'a btree) from lib/btree.ml into lib/example_functions.ml
oriba has joined #ocaml
dnh has joined #ocaml
azimut has joined #ocaml
average has joined #ocaml
bartholin has joined #ocaml
fweht has quit [Quit: Connection closed for inactivity]
boozec has joined #ocaml
darchitect has quit [Ping timeout: 268 seconds]
darchitect has joined #ocaml
azimut has quit [Remote host closed the connection]
<discocaml> <._null._> Usually you would just `open Btree`, but you can do `type 'a btree = 'a btree = Leaf | Node of... `
<discocaml> <._null._> Usually you would just `open Btree`, but you can do `type 'a btree = 'a Btree.btree = Leaf | Node of... `
azimut has joined #ocaml
boozec has quit [Quit: boozec]
rgrinberg has joined #ocaml
Tuplanolla has joined #ocaml
waleee has joined #ocaml
darchitect has quit [Ping timeout: 260 seconds]
darchitect has joined #ocaml
azimut has quit [Ping timeout: 255 seconds]
torretto has joined #ocaml
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
rgrinberg has joined #ocaml
alexherbo2 has quit [Remote host closed the connection]
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
average has quit [Quit: Connection closed for inactivity]
Anarchos has joined #ocaml
<discocaml> <Ada> how is printf able to change its arguments based on a string?
motherfsck has quit [Remote host closed the connection]
<discocaml> <Ada> i'm building a router and this would be an interesting way to handle parameters and query strings, but all i've found so far is ppx which seems rather complex
motherfsck has joined #ocaml
<discocaml> <octachron> Printf argument is not a string.
<discocaml> <octachron> It is a format string which is using a bit of special compiler support to share the same syntax as string.
<discocaml> <Ada> ahh,
<discocaml> <Kali> is there a way to concatenate format strings?
<discocaml> <Kali> ^^
<discocaml> <Kali> oh, found it
<discocaml> <octachron> "%s" is short-hand for `Format (String (No_padding, End_of_format), "%s")`
<discocaml> <octachron> Where `String` is a GADT constructor.
masterbuilder has joined #ocaml
<discocaml> <Ada> thank you, makes sense now
<discocaml> <Ada> so if i wanted to implement a similar system with type safety ppx would be the way to go 🙂
<discocaml> <octachron> If you want to keep the string like syntax, but you can pretty far in term of nice syntax with just GADTs + hlist without ppx
<discocaml> <Ada> thank you sm, i'll consider both
<discocaml> <octachron> You might also want to have a look at : https://github.com/anuragsoni/routes
<discocaml> <Ada> very nice looking
<discocaml> <Ada> if i want the string syntax and the learning experience its probably more practical than anything to build a ppx around that and let it handle the matching since it seems very robust
jabuxas has joined #ocaml
motherfsck has quit [Quit: quit]
motherfsck has joined #ocaml
<discocaml> <Kali> octachron: what's an hlist?
<discocaml> <octachron> A heterogeneous list
<discocaml> <octachron> For an example of one variant of heterogeneous lists.
<discocaml> <octachron> which can be used to replace `Format.fprintf ppf "%s %s n°%d" "Hello" "world" 6` with `fprintf ppf "%s %s n°%d" ["Hello"; "world"; 6 ]`.
<discocaml> <diligentclerk> I have an insane bug I don't know how to fix so here is a weird question, kind of a hail mary. If I compile OCaml with foreign C source code is it possible that OCaml's garbage collection strategy depends on the number of like, entry points exposed in the C code's header file
<discocaml> <diligentclerk> Because it seems like when I make unrelated changes to the C source code it triggers a segfault that I suspect is due to an accidental read after deallocation
jabuxas has quit [Ping timeout: 256 seconds]
<discocaml> <Kali> aha
<discocaml> <diligentclerk> and the only explanation I can come up with is that OCaml's garbage collection is behaving in a slightly different way as a function of the exposted signature of the C code
<discocaml> <diligentclerk> even when I make changes to functions that aren't actually called in the OCaml executable
<discocaml> <octachron> It sounds like you have a bug in your C code that is only lucky enough to trigger a segfault with the right code structure.
<discocaml> <diligentclerk> Well, I don't mean it's a bug in the OCaml garbage collector, I mean that the OCaml wrapper code for the C code registers certain foreign objects with the garbage collector and I suspect I somehow screwed this up.
<discocaml> <diligentclerk> In any case I don't know how to debug the C source code, it's transcompiled from another language and it's not really human readable. The \*.mli and \*.ml wrappers are also procedurally generated and I'm not thrilled about reading those in detail either.
<discocaml> <diligentclerk> Well, I don't mean it's a bug in the OCaml garbage collector, I mean that the OCaml wrapper code for the C code registers certain foreign objects with the garbage collector and I suspect I somehow screwed this up.
<discocaml> <diligentclerk> In any case I don't know how to debug the C source code, it's transcompiled from another language and it's not really human readable. The \*.mli and \*.ml wrappers are also procedurally generated and I'm not thrilled about reading the ml file in detail either.
<discocaml> <octachron> You could try to run lintcstubs on the C stubs; or insert call to the major GC after each call to C functions on the OCaml side to make the failure more deterministic.
mal`` has quit [Quit: Leaving]
Serpent7776 has quit [Ping timeout: 264 seconds]
Anarchos has quit [Quit: Vision[]: i've been blurred!]
mal`` has joined #ocaml
bartholin has quit [Quit: Leaving]
Tuplanolla has quit [Quit: Leaving.]
jabuxas has joined #ocaml