companion_cube changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 5.2.0 released: https://ocaml.org/releases/5.2.0 | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
mange has joined #ocaml
Everything has quit [Quit: leaving]
f[x] has quit [Remote host closed the connection]
hsw_ has joined #ocaml
hsw has quit [Read error: Connection reset by peer]
Haudegen has quit [Quit: Bin weg.]
Tuplanolla has quit [Quit: Leaving.]
f[x] has joined #ocaml
hsw_ has quit [Quit: Leaving]
hsw has joined #ocaml
f[x] has quit [Remote host closed the connection]
pi3ce_ has quit [Ping timeout: 255 seconds]
pi3ce has joined #ocaml
pi3ce has quit [Read error: Connection reset by peer]
pi3ce has joined #ocaml
ansiwen has quit [Quit: ZNC 1.7.1 - https://znc.in]
ansiwen has joined #ocaml
anpad has quit [Quit: ZNC 1.8.2 - https://znc.in]
anpad has joined #ocaml
mange has quit [Remote host closed the connection]
bartholin has joined #ocaml
<discocaml> <doraent> This is what I think aswell, but basically everytime we need to enforce the type of something we can use a .mli file/something lighter than a module type. It really looks like a java version translated to ocaml
<discocaml> <doraent> Sadly the maintainer does not answer any issue anymore, in fact the repo of the ocaml-version is dead (the book cannot even be built from there)
cr1901_ has joined #ocaml
cr1901 has quit [Ping timeout: 276 seconds]
bartholin has quit [Quit: Leaving]
myrkraverk has joined #ocaml
beo has joined #ocaml
Serpent7776 has joined #ocaml
zenes has quit [Ping timeout: 260 seconds]
<discocaml> <octachron> From my memory, the main issue is that some of the later examples need higher-kinded polymorphism, which need to go through functor in OCaml. And thus the OCaml version of the book decided to use functors even for basic function composition.
Haudegen has joined #ocaml
olle has joined #ocaml
mbuf has joined #ocaml
<discocaml> <doraent> yes but this is not only a choice, this is strictly speaking an error at some points. A good example is the very first snippet :
<discocaml> <doraent> ```ocaml
<discocaml> <doraent> module Compose_Example
<discocaml> <doraent> (F : Polymorphic_Function_F)
<discocaml> <doraent> (G : Polymorphic_Function_G with type b = F.b) =
<discocaml> <doraent> struct
<discocaml> <doraent> (** OCaml doesn't have a compose operator. So, creating one. **)
<discocaml> <doraent> let ( >> ) g f x = g (f x)
<discocaml> <doraent> let compose : 'a -> 'c = G.g >> F.f
<discocaml> <doraent> end
<discocaml> <doraent> ```
<discocaml> <doraent> here there is no need to declare 2 module types for F and G, and it does not even fit the idea of the haskell snippet.
<discocaml> <doraent> Moreover, some parts of the book are basically haskell-focused (not only the snippets), A very easy example is the string types in Ocaml/Haskell, in Haskell String = [Char] which is not true at all in Ocaml. I am pretty sure we can find tons of other examples (i found some in the parts about recursion, which is not handled exactly in the same way in ocaml and haskell)
<discocaml> <otini_> maybe it was translated from Haskell by someone who didn’t know or didn’t care about ocaml’s specificities?
<discocaml> <doraent> I am pretty sure it is the case, yes (and I think the objective of this "translation" was only to give ocaml snippets, and not fully express the book idea in ocaml)
hsw has quit [Remote host closed the connection]
hsw has joined #ocaml
mbuf has quit [Quit: Leaving]
f[x] has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
myrkraverk_ has joined #ocaml
myrkraverk has quit [Read error: Connection reset by peer]
theblatte has quit [Ping timeout: 252 seconds]
theblatte has joined #ocaml
theblatte has quit [Ping timeout: 245 seconds]
theblatte has joined #ocaml
Haudegen has joined #ocaml
trillion_exabyte has quit [Ping timeout: 276 seconds]
trillion_exabyte has joined #ocaml
toastal has quit [Ping timeout: 265 seconds]
toastal has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
toastal has quit [Quit: Gateway shutdown]
toastal has joined #ocaml
olle has quit [Ping timeout: 248 seconds]
Tuplanolla has joined #ocaml
<discocaml> <yawaramin> agree. i made an attempt but it's a big task https://github.com/hmemcpy/milewski-ctfp-pdf/pull/242
Everything has joined #ocaml
Haudegen has joined #ocaml
pi3ce has quit [Read error: Connection reset by peer]
pi3ce has joined #ocaml
<discocaml> <alyxshang> Chat can I have a hug
<discocaml> <alyxshang> I finally understood pointers
<discocaml> <alyxshang> I'm so happy I could cry
<discocaml> <._null._> Thanks to OCaml ?
<discocaml> <alyxshang> No, Ed from low-level-learniny and my old code.
<discocaml> <alyxshang> No, Ed from low-level-learning and my old code.
<discocaml> <alyxshang> I'm trying to keep the positive-feedback loop going.
<discocaml> <alyxshang> For learning things about my field I have missed.
<discocaml> <alyxshang> (That includes OCaml)
<discocaml> <._null._> Makes more sense, but good for you. As someone who forgot why pointers are difficult, what did you not understand ?
<discocaml> <alyxshang> I got confused between assigning a pointer to a mem location and dereferencing said pointer later on. The double use of the asterisk for either task.
<discocaml> <alyxshang> But I got it now.
<discocaml> <alyxshang> And that the "&" is a reference to the mem location of the created variable.
<discocaml> <._null._> That *p behaves similarly to p[0] for arrays so ? Where you both get and set them using the "same" syntax ?
kurfen has quit [Ping timeout: 252 seconds]
kurfen has joined #ocaml
<discocaml> <lukstafi> `[@@deriving sexp_of]` feature wish: in addition to `@opaque`, have a way to provide an alternative sexper... My workaround for a specific use case -- to break up sexping a recursive record, duplicate the record definition and in the second one use `[@@deriving sexp_of]`, for the first one manually write the sexper to output the record id.
<discocaml> <alyxshang> Well yes, but imagine how cryptic this was for a crab when it first had some C code between its pincers.
<discocaml> <._null._> I'm much less used to the situation in Rust, but I at least know that it's quite different
jsoo has quit [Ping timeout: 260 seconds]
<dh`> rust reference syntax is very confusing
<companion_cube> it's just & and * though?
<discocaml> <cristianoc> Not sure how relevant to this discussion, just adding some detail.
<discocaml> <cristianoc> In ReScript, currying in application is optional instead of the default. Making partial application opt-in.
<discocaml> <cristianoc> Plus, higher-order functions are explicit about the arity, which is a real change, though in practice the difference comes up less often than one would expect.
<discocaml> <cristianoc> (The motivation there is when interfacing with JavaScript directly one has to pay the price for the mismatch between ambiguous arity on one side and explicit arity on the other side).
<discocaml> <doraent> Basically we should do this everywhere, and even adapt the text to make it a real "ocaml version" and not juste ocaml snippets with some Haskell text
bartholin has joined #ocaml
<dh`> cube: rust? yes, except where it's not, and it's subtly different in places, and there are implicit conversions
<companion_cube> I'd love to hear more, to me it's fairly straightforward
<companion_cube> only place it's tricky is in patterns, and even then
<dh`> I have not used it that much yet and it may just be that the intro documentation is obfuscating it
<dh`> but there are definitely implicit conversions from scalar values to references to them
<dh`> which C specifically doesn't allow
<companion_cube> nope, never
<companion_cube> all references in rust are explicit
<companion_cube> a few _de_references are implicit in cases where it's obvious
szkl has quit [Quit: Connection closed for inactivity]
Serpent7776 has quit [Ping timeout: 252 seconds]
<dh`> ok, maybe I'm confused
<dh`> implicit dereferences are just as bad though
<companion_cube> having foo.x deference when foo is a reference sounds fine to me
<companion_cube> you don't gain much by disallowing that
<dh`> other than keeping a strict separation of concepts
<dh`> this is why C has ->
<companion_cube> it's just useless to separate the two in this case
<discocaml> <astreamingcomesacrossthesky> What are the optics on using archived libs in the OCaml-sphere? I wanna check out Bastet. Is it archived bc there's something wrong with it? Or is it merely stable and useable?
<discocaml> <deepspacejohn> (I assume you mean the "archived" status on the GitHub repo) I don't think archiving has any implicit meaning in the OCaml ecosystem. I'm not sure about Bastet specifically.
<discocaml> <astreamingcomesacrossthesky> Right, yeah, I do mean on GH. Good to know, thanks. I found it from a cursory search into category theory libraries but if there are others I'm glad to take recommendations. I know Base has cats stuff but I'm not sure I wanna bring in all that just for a small part of the whole.
Putonlalla has quit [Ping timeout: 260 seconds]
<discocaml> <alyxshang> Yeah, in Rust you just have an ampersand for refs and an asterisk for dereferencing things.
<discocaml> <alyxshang> Provided certain traits are implemented for the latter.
<companion_cube> no new language is keeping -> as a dereference operator, fwiw
<companion_cube> auto deref on field or method access is just the norm now
Anarchos has joined #ocaml
euphores has quit [Ping timeout: 248 seconds]
euphores has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
Haudegen has joined #ocaml
bartholin has quit [Quit: Leaving]
Haudegen has quit [Quit: No Ping reply in 180 seconds.]
Haudegen has joined #ocaml
<Anarchos> ir
<Anarchos> bonsoir
kurfen has quit [Quit: ZNC - https://znc.in]
kurfen has joined #ocaml
<dh`> right, in C you just have ampersand and star, but it's somehow not the same in a bunch of corners
<dh`> (besides the declaration syntax, where the C declaration syntax is awful)
<companion_cube> and -> like you said
Anarchos has quit [Remote host closed the connection]
Anarchos has joined #ocaml
<dh`> -> is purely syntactic though
<discocaml> <diligentclerk> I downloaded the Jane Street extensions and it's slower than my original code and I don't know why lmao
Everything has quit [Ping timeout: 260 seconds]
Everything has joined #ocaml
<discocaml> <diligentclerk> ```ocaml
<discocaml> <diligentclerk> let pi_approx : int -> float = fun n ->
<discocaml> <diligentclerk> let rec pi_sum k acc=
<discocaml> <diligentclerk> (if k = 0 then acc else pi_sum (k-1)
<discocaml> <diligentclerk> (acc +. 1./. (let a = float_of_int k in a *. a))) in
<discocaml> <diligentclerk> Float.sqrt @@ (6. *. pi_sum n 0.)
<discocaml> <diligentclerk> ;;
<discocaml> <diligentclerk>
<discocaml> <diligentclerk> let pi_approx_while n =
<discocaml> <diligentclerk> let acc = ref 0. in
<discocaml> <diligentclerk> let k = ref n in
<discocaml> <diligentclerk> while !k != 0 do
<discocaml> <diligentclerk> acc := !acc +. 1./. (let a = float_of_int !k in a *. a);
<discocaml> <diligentclerk> k := !k - 1
<discocaml> <diligentclerk> done;
<discocaml> <diligentclerk> Float.sqrt @@ 6. *. !acc
<discocaml> <diligentclerk> ```
<discocaml> <diligentclerk> With the Jane Street compiler, `pi_approx 1_000_000` is 50% slower and `pi_approx_while 1_000_000` is 100%-120% slower.
szkl has joined #ocaml
<discocaml> <Kali> avoid pasting code blocks in this channel
<discocaml> <Kali> each newline has to be sent as a separate message for the irc bridge
<dh`> and irc is resistant to that because of a multi-decade history of DoS attempts
<discocaml> <Kali> instead of "while !k != 0", you should use "while !k <> 0", and you can also use "decr k" for "k := !k - 1"
Haudegen has quit [Quit: Bin weg.]
f[x] has quit [Remote host closed the connection]
Anarchos has quit [Quit: Vision[]: i've been blurred!]