<d_bot>
<mimoo> is it possible to have an optional `val` in a `module type`?
<d_bot>
<mimoo> (I'm trying to add a `val param : bool` in an already existing module, but that means I'll have to change all existing code to set this to `false`. I was wondering if I could have that set to false by default in the `module type` so that most code can remain the same.
<d_bot>
<Shon F> Yeah, you can do that by using an `include BaseModule`, then shadow with the overriding value.
<d_bot>
<Shon F> ```
<d_bot>
<Shon F> module type S = sig
<d_bot>
<Shon F> val param : bool
<d_bot>
<Shon F> (* other stuff *)
<d_bot>
<Shon F> end
<d_bot>
<Shon F>
<d_bot>
<Shon F> module Default = struct
<d_bot>
<Shon F> let param = false
<d_bot>
<Shon F> (* other stuff *)
<d_bot>
<Shon F> end
<d_bot>
<Shon F>
<d_bot>
<Shon F> module Override = struct
<d_bot>
<Shon F> include Default
<d_bot>
<Shon F> let param = true
<d_bot>
<Shon F> (* other stuff *)
<d_bot>
<Shon F> end
<d_bot>
<Shon F> ```
<d_bot>
<Shon F> If you only have one param, this is obviously not any better than just defining the `param` in every implementation!
<d_bot>
<Shon F> But if you have several of these kinds of defaults, it can be useful.
<d_bot>
<mimoo> so you'd use destructive constraints here to set param = true?
<d_bot>
<Shon F> (Sorry for the ninja edit, I didn't read your question carefully enough at first)
<d_bot>
<Shon F> Do need a destructive constraint, cause this is at the value level.
<d_bot>
<Shon F> You're just shadowing the value from the "parent" module.
<d_bot>
<Shon F> It's just like doing
<d_bot>
<Shon F> ```
<d_bot>
<Shon F> let param = false
<d_bot>
<Shon F> let param = true
<d_bot>
<Shon F> (* param is true from on *)
<d_bot>
<Shon F> ```
<d_bot>
<Shon F> Except the first assignment is via the `include Default`
zebrag has quit [Read error: Connection reset by peer]
hackinghorn has joined #ocaml
zebrag has joined #ocaml
<d_bot>
<Shon F> (I cleaned up my suggestion a bit to show how you can have a "parent' module with default values, without having to have that parent fully implement your specification.)
<d_bot>
<mimoo> I see, thx!
<d_bot>
<mimoo> also, can I create a range and pass it to `for i in range do`?
dwt has joined #ocaml
dwt has quit [Client Quit]
dwt has joined #ocaml
jca has left #ocaml ["see you irc.libera.chat"]
kini has joined #ocaml
zebrag has quit [Quit: Konversation terminated!]
zebrag has joined #ocaml
dx has quit [Remote host closed the connection]
dx has joined #ocaml
astronavt has quit [Quit: ...]
astronavt has joined #ocaml
arecaceae has quit [Ping timeout: 240 seconds]
infinity0 has quit [Ping timeout: 240 seconds]
arecaceae has joined #ocaml
infinity0 has joined #ocaml
zebrag has quit [Quit: Konversation terminated!]
zebrag has joined #ocaml
<d_bot>
<mimoo> ok, question about js_of_ocaml. I can't seem to enforce that my input is an array of uint8Array
<d_bot>
<mimoo> ```
<d_bot>
<mimoo> type 'a array_js = 'a Js.js_array Js.t
<d_bot>
<mimoo> type u8_array_js = Js_of_ocaml.Typed_array.uint8Array Js.t
<d_bot>
<mimoo> let some_function (some_input : u8_array_js array_js) = ...
<d_bot>
<mimoo> ```
<d_bot>
<mimoo> in theory this should only accept an array of uint8array, but I can pass a uint8array directly and it works : |