<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> 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?
<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