companion_cube changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 5.0 released(!!1!): https://ocaml.org/releases/5.0.0.html | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
dnh has joined #ocaml
dnh has quit [Client Quit]
Tuplanolla has quit [Quit: Leaving.]
xd1le has joined #ocaml
mima has quit [Ping timeout: 255 seconds]
wingsorc has joined #ocaml
<companion_cube> octachron: is it normal that many functions in `List` are still not TRMC? e.g. merge, combine, remove_assq, remove_assoc
<discocaml> <sixilli> Ik this is super vague, but how do functional languages handle polymorphism like this? I'm trying to achieve something similar but my brain is too deep in OOP
<discocaml> <sixilli>
<discocaml> <sixilli> ```ocaml
<discocaml> <sixilli> let get_area (obj: Shape): float = obj.area()
<discocaml> <sixilli> ```
<companion_cube> depends on what tradeoff you want.
<companion_cube> some runtime overhead: you could use objects to represent shapes
<companion_cube> fast but not extensible: make shape a sum type, and `get_area` a pattern match
<discocaml> <sixilli> I think I might need to use objects. I need to create something somewhat generic that can attempt to get a values using a string then return a string, bool, or list of string.
<discocaml> <sixilli> I think I might need to use objects. I need to create something somewhat generic that can attempt to get a values from a record using a string then return a string, bool, or list of string.
<companion_cube> the string, bool, or list of string, at least, is a sum type :)
<companion_cube> but otherwise, maybe objects are the answer, maybe not
<companion_cube> they're nearly not as pervasive as in C++
<discocaml> <sixilli> Yeah I'll have to look around some more. Because the number of records will be generated dynamically. So I need a way to pull data from them by field name. I could also generate code to create a hashtbl with key string, then the sum type?
<companion_cube> if you generate code, a sum type + functions on it is actually pretty great
<companion_cube> (no need for a hashtable in that case, it can all be done in code)
<discocaml> <sixilli> I'm still in the early stages but I'm parsing templates -> generating a record so users can put data in the record -> getting the record back and using it to render the template. The render step needs to be generic and not hardcoded, so looking up values is pretty difficult. So far a hash map has made the most sense lol
<discocaml> <sixilli> I'm still in the early stages but I'm parsing templates -> generating records so users can put data in the record -> getting the record back and using it to render the template. The render step needs to be generic and not hardcoded, so looking up values is pretty difficult. So far a hash map has made the most sense lol
<companion_cube> you mean like html templates?
<discocaml> <sixilli> Yee
<discocaml> <sixilli> I've been diggind through some other projects to see how they handle it. I wanted to build something more user friendly by generating records.
<discocaml> <sixilli> ```ocaml
<discocaml> <sixilli> let html_loader = "./templates" [@@deriving html_templating]
<discocaml> <sixilli>
<discocaml> <sixilli> (* code that gets generated from some PPX *)
<discocaml> <sixilli> type my_page_params = { hello: string; world: string; is_admin }
<discocaml> <sixilli> let render_my_page (params: my_page_params): string =
<discocaml> <sixilli> let build_ctx params =
<discocaml> <sixilli> (* todo ??? *)
<discocaml> <sixilli>
<discocaml> <sixilli> MyTemplateModule.parse("my_page.html", build_ctx params)
<discocaml> <sixilli> ```
<discocaml> <sixilli> idk how possible this is, but this was the code I was trying to generate
<discocaml> <sixilli> ```ocaml
<discocaml> <sixilli> let html_loader = "./templates" [@@deriving html_templating]
<discocaml> <sixilli>
<discocaml> <sixilli> (* code that gets generated from some PPX *)
<discocaml> <sixilli> type my_page_params = { hello: string; world: string; is_admin: bool }
<discocaml> <sixilli> let render_my_page (params: my_page_params): string =
<discocaml> <sixilli> let build_ctx params =
<discocaml> <sixilli> (* todo ??? *)
<discocaml> <sixilli>
<discocaml> <sixilli> MyTemplateModule.parse("my_page.html", build_ctx params)
<discocaml> <sixilli> ```
<discocaml> <sixilli> kinda like ppx_show for html templates
<companion_cube> ah kind of fun, yeah
<companion_cube> starting with a ppx is a bit hardcore though :)
<companion_cube> I wonder, I think I'd probably write one generic render function that takes a hashtable (like you say), and if I had a ppx I'd generate code to go from the custom record of each template, to this hashtable
<companion_cube> (or alternatively generate a function `the_record -> string -> string option` that serves as lookup)
<discocaml> <sixilli> Yeah that's exactly what I was thinking. Because the record is much more user friendly. I think the 2nd option gets harder when I need a list. I suppose I could use a sum type for that. 🤔
<companion_cube> if you want it to be nice to _use_, the record is good I think
<companion_cube> if you code-generate it that is
<discocaml> <sixilli> Yeah I think I've now decided that I will let the user use the recored, then when they call the render fn it will map the record to a hash map that will get passed to the parser.
<companion_cube> 👍
<discocaml> <sixilli> tyty for talking that through with me
<discocaml> <sixilli> 🦆
<companion_cube> quack
terrorjack has quit [Quit: The Lounge - https://thelounge.chat]
terrorjack has joined #ocaml
<discocaml> <barconstruction> this might be overkill but maybe you define a module type `Shape`
<discocaml> <barconstruction> that exposes a type `t` and a function `val area : t -> float`
steenuil has quit [Remote host closed the connection]
steenuil has joined #ocaml
steenuil_ has joined #ocaml
steenuil has quit [Ping timeout: 255 seconds]
steenuil_ is now known as steenuil
waleee has quit [Ping timeout: 252 seconds]
bartholin has joined #ocaml
<discocaml> <gooby_clown> I think libs often use libsexp for this
<discocaml> <gooby_clown> Which is just serialization
<discocaml> <gooby_clown> So that's another option
mima has joined #ocaml
bartholin has quit [Quit: Leaving]
Serpent7776 has joined #ocaml
dnh has joined #ocaml
Serpent7776 has quit [Ping timeout: 252 seconds]
mro has joined #ocaml
wingsorc has quit [Ping timeout: 256 seconds]
migalmoreno has joined #ocaml
edr has joined #ocaml
migalmoreno has quit [Changing host]
migalmoreno has joined #ocaml
Serpent7776 has joined #ocaml
migalmor` has joined #ocaml
migalmor` has quit [Remote host closed the connection]
dnh has quit [Remote host closed the connection]
dnh has joined #ocaml
<companion_cube> serialization?!
<discocaml> <octachron> @barconstruction , the subarray change in https://github.com/ocaml/ocaml/pull/12754 seems to fix a lot of the performance issue in your numerical example. I am still investigating if there is something deeper at play.
mro has quit [Quit: Leaving]
noonien85 has quit [Ping timeout: 255 seconds]
<discocaml> <barconstruction> hey thank you very much. i found this gh issue and was wondering if they were related, i appreciate the follow up!
<discocaml> <barconstruction> @octachron
<vsiles> hi folks ! I'm witnessing something really strange with Core: https://pastebin.com/KhekNxWk
<vsiles> Core.String seems to point to Caml.String instead of the String module in Core, making things like Core.String.Map unavailable
<vsiles> did I miss anything new ?
<vsiles> looks like I need to do just `Map.find` now... migration pain is on the way
dhil has joined #ocaml
dnh has quit [Remote host closed the connection]
dnh has joined #ocaml
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Tuplanolla has joined #ocaml
jmiven has quit [Quit: reboot]
bartholin has joined #ocaml
szkl has joined #ocaml
Guest97 has joined #ocaml
<Guest97> Hi! do you know libraries/papers that describe how to hide stack memory management with monads? I came up with this pretty basic example `let ( let* ) x f = let ltop = get_stack_pointer () in  let res = f x in clean_stack_up_to_copy ltop res`
<Guest97> where clean_stack_up_to_copy ltop res cleans the stack from ltop to the connected object res and returns res
dnaq has quit [Remote host closed the connection]
dnaq has joined #ocaml
dnh has joined #ocaml
dnh has quit [Client Quit]
waleee has joined #ocaml
dnh has joined #ocaml
Anarchos has joined #ocaml
dnh has quit [Ping timeout: 256 seconds]
dnh has joined #ocaml
<Guest97> with ctypes, can you create a pointer to a value without allocating a new value with Ctypes.allocate?
motherfsck has quit [Read error: Connection reset by peer]
dhil has quit [Ping timeout: 260 seconds]
Guest97 has quit [Quit: Client closed]
Guest97 has joined #ocaml
<Guest97> tried this: `let addr = Ctypes.(raw_address_of_ptr (to_voidp v)) in Ctypes.(coerce Ctypes.(ptr void)  (ptr target_type) (ptr_of_raw_address addr))`
<Guest97> causes segfault when passed to a C function
motherfsck has joined #ocaml
mima has quit [Ping timeout: 264 seconds]
wingsorc has joined #ocaml
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
xd1le has quit [Quit: xd1le]
wingsorc has quit [Read error: Connection reset by peer]
<Guest97> mb this to_voidp is wrong
Serpent7776 has quit [Ping timeout: 255 seconds]
dnh has joined #ocaml
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bartholin has quit [Quit: Leaving]
Anarchos has quit [Quit: Vision[]: i've been blurred!]