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/
Tuplanolla has quit [Ping timeout: 260 seconds]
alphacentauri has quit [Quit: WeeChat 4.0.5]
waleee has quit [Ping timeout: 260 seconds]
<discocaml> <darrenldl> i am teaching java and had an implementation of binary search tree to refer to that was heavily reference/pointer fiddling based
<discocaml> <darrenldl> suffice to say the version i wrote that follows the fp style is much easier to understand, but needing to tip toe around java syntax was annoying
waleee has joined #ocaml
<discocaml> <darrenldl> the elegance is unmatched by c and java definitely
waleee has quit [Ping timeout: 272 seconds]
<src> I'm trying to finally clear my confusion on `;;`, I'm working through the well known CS3110 course/book and since it uses the toplevel almost exclusively (so far at least) but I wanted to write code to source files I ended up sprinkling `;;` a lot to make my environment to fix all kinds of syntax/expression errors etc
<src> now I get `;;` aren't need at all in OCaml, and it's idiomatic to wrap expressions where I don't care about their return in `let` expressions, using wildcard pattern `_` to discard the return, so `let _ = Printf.printf "%s\n" (myfunc 5)` for example
<src> but this way I still can't have multiple `Printf.printf` statements in a row correct? Either I use `;;` to separate them or prepend `let _ = `on all of them, correct?
<src> so intead of using `;;` I end up using `let _ = ` for every Printf.printf?
<discocaml> <Kali> that's what ; is for
waleee has joined #ocaml
<discocaml> <Kali> `;` is sort of like a binary operator that takes a unit-returning expression on its left and returns whatever is on its right
<discocaml> <Kali> its left side is executed first
<discocaml> <Kali> this is how you chain effects
<src> so in other ways disregards the left sides return so the return of the whole expression becomes what's most-right in the `expr ; expr; expr;` chain
<src> makes sense that this solves the issue yeah
<discocaml> <Kali> no ; at the end
<discocaml> <Kali> but yes
<src> sorry yep, the last one isn't needed
<src> it's not a terminator but a separator I get it
<discocaml> <Kali> yep
<src> sooo... since every Printf.printf by itself evaluates to `()`, if I wrap multiple Printf.printf calls into the same `let _ = ` it's like I have multiple return values in that let expression
<src> therefore the `;` is needed? is that logic right?
<src> (just want to make sure I got it)
waleee has quit [Ping timeout: 260 seconds]
<discocaml> <Kali> yes, because just putting them next to each other would mean applying () to () which is obviously a type error
<src> Ah awesome
<src> good explanation
<src> thanks a ton
<discocaml> <Kali> `let _ = ...` is equivalent to `ignore (...)`, btw
<discocaml> <Kali> ignore : 'a -> unit
<discocaml> <Kali> er, `let _ = ... in ()`
<companion_cube> Just use `let () =... ` btw
<companion_cube> It prevents silent partial applications
<src> and `;;` working in source files at all can be regarded as a historical artifcact?
<src> for backwards compatibility with older versions of ml?
<discocaml> <akhilindurti> is there a reason why `;` is defined to only accept unit?
<discocaml> <akhilindurti> is there a reason why `;` is defined to only accept `unit`?
<discocaml> <akhilindurti> like it could have been defined to work on `'a` right? and then you could use it as `ignore`
<discocaml> <akhilindurti> ig that would be less safe from a programming pov
<discocaml> <Kali> chaining and ignoring pure functions is just wasted computation
<discocaml> <Kali> or even partially applied impure functions
<src> mhmh since `;;` does "work"/is legal in OCaml source code what would be a one sentence description of what it actually does?
<discocaml> <Kali> ;; terminates a toplevel expression or declaration
<discocaml> <leviroth> `;` is not actually defined to only accept unit
<discocaml> <Kali> this is necessary in the repl because the repl does not send expressions on newline
<src> I see
<discocaml> <leviroth> There’s some compiler warning that I think is by default promoted to an error, but you can disable the warning and do 1; 2 if you want
<discocaml> <Kali> it is unnecessary in source files because the start and end of a declaration can always be inferred assuming the lack of toplevel expressions
<discocaml> <akhilindurti> ahh right my bad
<discocaml> <akhilindurti> i should disable that warning then
<discocaml> <Kali> no, you shouldn't
<discocaml> <Kali> why would you?
<discocaml> <Kali> assuming the expression is pure, you're just wasting computation, and if it isn't, then you can just use ignore
<discocaml> <Kali> side-effecting functions which return non-unit values are very rare, at least in the stdlib
<discocaml> <Kali> er, sorry, let me rephrase that
<discocaml> <akhilindurti> yeah to replace some uses of `ignore`
<discocaml> <akhilindurti> i guess `ignore` is clearer to the reader
<discocaml> <Kali> ignore is far less error-prone
<discocaml> <akhilindurti> like i have this
<discocaml> <akhilindurti> ```ocaml
<discocaml> <akhilindurti> ignore
<discocaml> <akhilindurti> (List.fold_left td.instances ~init:[] ~f:(add_instance env td.name));
<discocaml> <akhilindurti> ```
<discocaml> <akhilindurti> which could be re-written to
<discocaml> <akhilindurti> ```ocaml
<discocaml> <akhilindurti> List.fold_left td.instances ~init:[] ~f:(add_instance env td.name);
<discocaml> <akhilindurti> ```
<discocaml> <Kali> what happens when you forget to apply a side-effecting function fully and don't get warned about it because you disabled the nonunit error?
<discocaml> <akhilindurti> true
<discocaml> <Kali> ignore is far clearer anyway
<discocaml> <Kali> i would be very confused if i read the second version
tizoc has quit [Quit: Coyote finally caught me]
tizoc has joined #ocaml
<discocaml> <Kali> what does that snippet do? i am suspicious you should be using iter rather than fold here
<discocaml> <akhilindurti> it loops over the instances to check if they overlap (for coherency). the fold is needed, because we need to keep track of instances that have already been added to the set
<discocaml> <akhilindurti> but we don't need the set afterwards
<discocaml> <Kali> i see
<src> mhm it seems that a comment after a let expression indents wrongly for me?
<src> if I do `;;` at the end the subsequent comment aligns to the left as I would like it to...
<src> annoying
chrisz has quit [Ping timeout: 240 seconds]
chrisz has joined #ocaml
ansiwen has quit [Quit: ZNC 1.7.1 - https://znc.in]
ansiwen has joined #ocaml
Serpent7776 has joined #ocaml
bartholin has joined #ocaml
Serpent7776 has quit [Ping timeout: 240 seconds]
azimut_ has quit [Ping timeout: 252 seconds]
<discocaml> <badems> Hello when to us « Prinf.prinf, or print_ please ?
Serpent7776 has joined #ocaml
mro has joined #ocaml
alphacentauri has joined #ocaml
average has quit [Quit: Connection closed for inactivity]
average has joined #ocaml
dnh has joined #ocaml
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
pkal has joined #ocaml
dnh has joined #ocaml
<pkal> Is thers some alternative document to document the META file format?
<pkal> the man page is not that helpful
<pkal> or some collection of examples?
jlrnick has joined #ocaml
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
dnh has joined #ocaml
jlrnick has quit [Ping timeout: 255 seconds]
david2 has joined #ocaml
david2 has quit [Client Quit]
<hannes> is there a path to have domain-local variables in OCaml 5, where I use global variables in OCaml 4? (bonus points if I could write code that does the right thing [tm] on both OCaml versions)
<hannes> i.e. a "let running = ref false" in OCaml 4 is fine, but racey in OCaml 5... But the whole Domain. API is not available in OCaml 4 (is Domain even the right thing? Maybe Atomic?)
<hannes> ah, there's gasche's domain-shims
pkal has left #ocaml [Killed buffer]
rock64 has joined #ocaml
<rock64> Simple switch to tell opam to use multiple cpus?
<rock64> Taking forever on my poor rockpro64 pine64 chip :d
<rock64> hm jobs: 4 in .opam/config
<rock64> The rockpro64 has 6 cores, but of course they're quite slow
<rock64> Guess I'll just wait :)
<rock64> "jobs" != cores used for a single job, I guess
rock64 has quit [Read error: Connection reset by peer]
rock64 has joined #ocaml
midgard has quit [Quit: Bye]
midgard has joined #ocaml
rock64 is now known as olle
<octachron> olle, this discuss thread is out-of-date, the current opam package for the compiler does use -j jobs
<olle> octachron: ok, but that's still not cpus per one job, right?
<octachron> the compiler is built with "make -j $(opam var jobs)" with opam
<olle> ah ok
<olle> thanks :)
jlrnick has joined #ocaml
jlrnick has quit [Read error: Connection reset by peer]
<olle> Weird, my ocaml system 5.1 is not listed in opam switch
<olle> I'm on Armbian at the moment
<olle> opam install dune fails because of this mismatch, it seems
<olle> Some command to update it missing?
<olle> eval $(opam env) does not solve it
mro has quit [Quit: Leaving]
<zozozo> olle: have you done an `opam update` recently ?
Serpent7776 has quit [Quit: WeeChat 1.9.1]
waleee has joined #ocaml
waleee has quit [Ping timeout: 255 seconds]
waleee has joined #ocaml
waleee has quit [Ping timeout: 260 seconds]
waleee has joined #ocaml
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
olle has quit [Read error: Connection reset by peer]
waleee has quit [Ping timeout: 272 seconds]
waleee has joined #ocaml
dnh has joined #ocaml
azimut has joined #ocaml
terrorjack has quit [Quit: The Lounge - https://thelounge.chat]
terrorjack has joined #ocaml
waleee has quit [Ping timeout: 255 seconds]
ec has quit [Ping timeout: 252 seconds]
ec has joined #ocaml
ec has quit [Ping timeout: 252 seconds]
ec has joined #ocaml
ec has quit [Remote host closed the connection]
ec has joined #ocaml
waleee has joined #ocaml
Serpent7776 has joined #ocaml
Anarchos has joined #ocaml
bartholin has quit [Quit: Leaving]
Anarchos has quit [Quit: Vision[]: i've been blurred!]
Anarchos has joined #ocaml
<Anarchos> how to tell opam to install from the latest revision of the github repo for a package ?
Everything has left #ocaml [#ocaml]
<Anarchos> thanks Alizter for this nice one : https://github.com/ocaml/dune/pull/8795 !!
Anarchos has quit [Quit: Vision[]: i've been blurred!]
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Tuplanolla has joined #ocaml
waleee has quit [Ping timeout: 240 seconds]
waleee has joined #ocaml
dnh has joined #ocaml
<discocaml> <froyo> smasher164: your use of `List.fold_left` is just an allocating `List.iter`
waleee has quit [Ping timeout: 272 seconds]
<discocaml> <akhilindurti> don't know what you mean by allocting List.iter. i need the instance list as an accumulator, is that what you mean?
<discocaml> <akhilindurti> `add_instance` looks like
<discocaml> <akhilindurti> ```ocaml
<discocaml> <akhilindurti> let add_instance env trait_name ins_list (ins_qty, _) =
<discocaml> <akhilindurti> List.iter ins_list ~f:(fun qty ->
<discocaml> <akhilindurti> if overlap env qty ins_qty then
<discocaml> <akhilindurti> raise (overlapping_instance trait_name ins_qty));
<discocaml> <akhilindurti> ins_qty :: ins_list
<discocaml> <akhilindurti> ```
<discocaml> <akhilindurti> so it threads through the instance list
waleee has joined #ocaml
<discocaml> <akhilindurti> don't know what you mean by allocating List.iter. i need the instance list as an accumulator, is that what you mean?
<discocaml> <akhilindurti> to turn this into a List.iter, I'd have to make `ins_list` a mutable ref
Serpent7776 has quit [Ping timeout: 272 seconds]
alphacentauri has quit [Quit: WeeChat 4.0.5]
alphacentauri has joined #ocaml
david2 has joined #ocaml
david2 has quit [Client Quit]
justache is now known as justHaunting
alphacentauri has quit [Quit: WeeChat 4.0.5]
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
waleee has quit [Ping timeout: 255 seconds]
waleee has joined #ocaml
alphacentauri has joined #ocaml
<discocaml> <lfwb> Hallo!