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/
malte has quit [Ping timeout: 272 seconds]
malte has joined #ocaml
malte has quit [Remote host closed the connection]
malte has joined #ocaml
malte has quit [Remote host closed the connection]
malte has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 265 seconds]
wbooze has joined #ocaml
wbooze has quit [Ping timeout: 272 seconds]
malte has quit [Remote host closed the connection]
malte has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
malte has quit [Remote host closed the connection]
malte has joined #ocaml
Mister_Magister has quit [Quit: bye]
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #ocaml
malte has quit [Remote host closed the connection]
alfiee has joined #ocaml
Mister_Magister has joined #ocaml
malte has joined #ocaml
alexherbo2 has quit [Remote host closed the connection]
alfiee has quit [Ping timeout: 244 seconds]
malte has quit [Remote host closed the connection]
malte has joined #ocaml
malte has quit [Remote host closed the connection]
malte has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 248 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
Tuplanolla has quit [Quit: Leaving.]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
alfiee has joined #ocaml
ski has quit [Ping timeout: 245 seconds]
alfiee has quit [Ping timeout: 252 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 268 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 260 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 248 seconds]
wbooze has joined #ocaml
YuGiOhJCJ has quit [Quit: YuGiOhJCJ]
alfiee has joined #ocaml
Serpent7776 has joined #ocaml
alfiee has quit [Ping timeout: 260 seconds]
Exa has quit [Read error: Connection reset by peer]
Exa has joined #ocaml
Exa has quit [Quit: see ya!]
Exa has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
Haudegen has joined #ocaml
bartholin has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 260 seconds]
bartholin has quit [Quit: Leaving]
Tuplanolla has joined #ocaml
wbooze has quit [Quit: Leaving]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
wbooze has joined #ocaml
ski has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 276 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 268 seconds]
wbooze has quit [Ping timeout: 246 seconds]
sroso has quit [Quit: Leaving :)]
olle has joined #ocaml
malte has quit [Remote host closed the connection]
wbooze has joined #ocaml
alexherbo2 has joined #ocaml
Exagone313 has joined #ocaml
Exa has quit [Read error: Connection reset by peer]
alfiee has joined #ocaml
Exagone313 is now known as Exa
alfiee has quit [Ping timeout: 244 seconds]
wbooze has quit [Quit: Leaving]
wbooze has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
Exa has quit [Read error: Connection reset by peer]
Exa has joined #ocaml
Exa has quit [Client Quit]
Exa has joined #ocaml
Exagone313 has joined #ocaml
Exa has quit [Read error: Connection reset by peer]
Exagone313 has quit [Remote host closed the connection]
Exa has joined #ocaml
Exa has quit [Quit: see ya!]
Exa has joined #ocaml
Exa has quit [Read error: Connection reset by peer]
Exagone313 has joined #ocaml
Exagone313 is now known as Exa
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
Haudegen has joined #ocaml
ygrek has joined #ocaml
chrisz has quit [Remote host closed the connection]
wbooze has quit [Ping timeout: 252 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
wbooze has joined #ocaml
<za3k> I have finished (more or less) my first OCaml program, and I would love a code review
<za3k> Warning, it's about 1K lines of code
<za3k> It doesn't use anything outside of the standard library
<za3k> It's a multi-user text editor, designed for several people SSH-ed into one machine, otherwise it's a low-feature-count nano clone
szkl has quit [Quit: Connection closed for inactivity]
<za3k> https://blog.za3k.com/multi-user-text-editor/ (includes screenshot and code link)
<za3k> If someone wants to take me up, feel free to either /msg me high-level feedback, or I can create a github PR where you can comment on specific lines more easily
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
Haudegen has quit [Quit: Bin weg.]
alexherbo2 has quit [Remote host closed the connection]
olle has quit [Ping timeout: 252 seconds]
bartholin has joined #ocaml
<discocaml> <contificate> it's a neat first project in OCaml
<discocaml> <contificate> you'd prefer pattern matching over doing something like this: https://github.com/za3k/text-multiedit/blob/master/args.ml#L53-L56
<discocaml> <contificate> I'd prefer patterns over `fst`, `snd`, etc. usage (unless in the higher order context), that way you can document other components, e.g. `let (x, _foo) = ...`
<discocaml> <contificate> style wise, I never really approve of `@@¬
<discocaml> <contificate> style wise, I never really approve of `@@`
<discocaml> <contificate> almost certainly don't need that many `Unix.` prefixes on https://github.com/za3k/text-multiedit/blob/master/client.ml#L191-L194, can do it outer or on the first component only (usually)
<discocaml> <contificate> anyway, I'll avoid posting walls of text - nothing jumps out as me as outrageous
<za3k> do you prefer |> or parens?
<za3k> i'm freely using a mix of all three
<discocaml> <contificate> depends on context, I almost never care for `|>` on a single line, but others do
<discocaml> <contificate> the nicest case of `|>` is definitely when it's over lines and you can independently comment some line out, like with an emacs shortcut
<za3k> Say more about unix prefixes?
<discocaml> <contificate> you can probably avoid prefixing every field of the record, usually it suffices to do something like `let x = Foo.{ x = ..; ... }` or `let x = { Foo.x = ...; ... }`
<discocaml> <contificate> I'd be tempted to introduce a record here https://github.com/za3k/text-multiedit/blob/master/types.ml#L35C5-L35C112
<za3k> I don't know .{ and .(, I'll have to learn them
<za3k> I didn't understand the second method at all
<za3k> Yeah I tend to agree. Is there a way to introduce a record without having a named type for it?
<discocaml> <contificate> in ADTs, yes
<discocaml> <contificate> `Foo of { x: int; ... }`
<discocaml> <contificate> there's no anonymous record types in OCaml, but I think there's a Jane Street proposal to add labelled tuples or something
<za3k> is this an ADT?
<discocaml> <contificate> yeah, `receive_action` is an algebraic datatype
<discocaml> <contificate> with ReplaceText as one of its constructors/alternatives/variants/...
<discocaml> <contificate> I'm a bit of a sinner, but things like `Unix.tcsetattr Unix.stdin Unix.TCSADRAIN termio ` would be `Unix.(tcsetattr stdin TCSADRAIN termio)` if I did it, but that can really bite you in some cases
<za3k> is that shorthand for "let open Unix in ( ... )" ?
<discocaml> <contificate> yes
<za3k> I thought I had tried an anonymous record and gotten a compilation error
<za3k> so one mystery in server.ml
<discocaml> <contificate> https://github.com/za3k/text-multiedit/blob/master/display.ml#L105C21-L105C59 this is probably fine here, but in generaly, it can sometimes be good to look for fusion opportunities (which may not always be safe in a language like OCaml, hence are not done by the compiler)
<za3k> if I move process_actions inside of server_main, I get a syntax error
<za3k> and I have no idea why
<za3k> yeah there are much more pressing efficiency concerns, I need to rewrite text.ml generally
<discocaml> <contificate> it should be fine to nest that function under that, it should be do-able: I'd avoid it here, I try to avoid huge functions with lots of nested dependencies
<za3k> it does something like iterate over the entire document for every character displayed, which is one per character typed
<za3k> yeah i wasn't going to tear up about having to take it out, but I wasn't sure why I was getting the error
<za3k> I am especially proud of input.ml and output.ml
<discocaml> <contificate> https://github.com/za3k/text-multiedit/blob/master/types.ml#L52C1-L53C22 fun fact, `ref` is really a function that embeds a value into a single element record whose lone field is marked as `mutable`, so this is one extra indirection, it can just be `mutable state: state;`, then update with `<-`
<discocaml> <contificate> e.g. `type 'a ref = { mutable contents: 'a; }`
<za3k> oh yeah i forgot about mutable records
<discocaml> <._null._> Mutable record fields*
<discocaml> <contificate> it's interesting that you didn't use `dune` and your makefile invokes the bytecode compiler, I tend to default to `ocamlopt` on everything
<discocaml> <contificate> oh wait you do invoke it
<za3k> i need to run on another machine which has an older libc
<za3k> and yes, ocamlopt :)
<za3k> which is a TERRIBLE name, it sounds optional or like it generates options
<za3k> i assume it's "optimized" or something
<discocaml> <contificate> yeah, the compiler that targets native
<za3k> so my next step is that my files are sort of split up in an awkward way because of dependency ordering
<discocaml> <contificate> it gets better, there's also ocamlc.opt which is the bytecode-targeting compiler compiled with ocamlopt
<za3k> i assume if I make some .mli files i can fix that
<discocaml> <._null._> Probably "optimizing", since the compiler itself isn't particularly more optimised
<za3k> but i'm not sure how to generate them with ocaml tooling
<za3k> when I tried -i naively i got lots of dependency errors where it failed to compile
alfiee has joined #ocaml
<za3k> for example a lot of stuff depends on 'debug.ml' and it depends on a lot of types from other files
<za3k> it's just all the pretty-printers in a separate file
<za3k> hmm i'd suggest we should go to DM to avoid annoying other people with extended discussion, but that's hard when you're on discord and i'm on IRC
<za3k> so i feel like you've mentioned a lot of small-scale stylistic stuff
<za3k> big-picture is there restruturing needed, or whole areas I should learn about?
<za3k> also i've sort of just made up my own style with no reference to existing code
<za3k> in terms of line breaks and indents and so on
<discocaml> <contificate> I'd get familiar with dune anyway
alfiee has quit [Ping timeout: 248 seconds]
<za3k> yeah if/when I do another project i will
<za3k> it seemed... heavyweight
<za3k> and then when I wanted static binary compilation it seemed like it was a huge pain in dune and I didn't want to switch at that point
<discocaml> <._null._> If your project works with a single folder containing everything, it's just two files of 1 and 3-5 lines
<za3k> i want to learn it whether i decide to use it
<za3k> so for example I had no idea how to include the same files in tests and a binary
<za3k> i'm sure this is easy stuff
<discocaml> <contificate> probably factor the shared bit into a library of its own
<za3k> also i was getting fed up with all these cryptic commands like "dune init" that ended up making a one-line file i could have #($ written myself
<discocaml> <contificate> yeah, I've never used dune init
<za3k> yeah well i looked for a dune tutorial
<za3k> uh yeah so any advice to generate an .mli file
<discocaml> <contificate> they're a bit sparse, I think there's insights into dune that are simply key to using it effectively
<discocaml> <contificate> there's cmitomli
<za3k> i think that's about my only specific question
<discocaml> <contificate> and merlin can do it as well
<za3k> well appreciate the review
<discocaml> <contificate> yeah, sorry it's only surface level/feature stuff, lots of effort to sit down and do a semantic review at scale
<za3k> no that's totally valid, i wasn't expecting someone to sit down for an hour or more
<za3k> stuff like "hey you're not using dune" or "wow, there's a lot of Unix." is fine :)
<za3k> i learned at *least* three things
<za3k> i'm at the phase where my response to "maybe you should use X" is usually "wait, what's X?"
<za3k> learning lots of new tools
<discocaml> <._null._> On that subject, are you using the LSP or merlin ?
<za3k> no, just vim
<discocaml> <contificate> this should be `fun` https://github.com/za3k/text-multiedit/blob/master/client.ml#L41
<discocaml> <._null._> You should set it up, there's an opam package for easy setups
<za3k> why should it be fun?
<discocaml> <contificate> it's an irrefutble pattern
<discocaml> <._null._> (user-setup)
<discocaml> <contificate> irrefutable*
<za3k> won't they be equivalent?
<discocaml> <contificate> they will
<za3k> i'm missing the bit where irrefutable pattern = use fun
<za3k> also, can you do pattern matching inside function arguments, like unpack a tuple or record?
<discocaml> <contificate> yes
<za3k> WHAT
<za3k> game changer
<discocaml> <._null._> You can do `let f (x, y) = x + y`, so you have no reason to write `let f = function (x, y) -> x + y`
<za3k> sorry i mean inside let-defined functions
<za3k> WHAT
wbooze has quit [Ping timeout: 265 seconds]
<discocaml> <contificate> `function` is an anonymous function that's defined by cases you provide, `e.g. function None -> 1 | Some c -> c`
<za3k> wild
<za3k> yeah i knew 'function' i just didn't know i could do it the other way
<discocaml> <contificate> `fun <pat>+ -> <expr>` is the other case, which is typically used with irrefutable patterns
<za3k> i swear i tried this, must have messed it up
<discocaml> <._null._> You can even do `let f { x; _ } = x`
<za3k> also i need to learn how to do "don't care" for records on the left hand side
<za3k> ^ and that's how, thanks null
<discocaml> <contificate> side doesn't matter, you can list them in any order
<discocaml> <._null._> Well, my previous message
<za3k> LHS as in A = B sides
<za3k> it's a compiler term of art, maybe
<za3k> LVal sometimes
<discocaml> <contificate> another thing you may dislike (as I'm not fond of) is that you can actually do like `x.Foo.y` when `x : Foo.some_record_type`
<discocaml> <contificate> which you don't need if it's annotated or local or whatever
<discocaml> <._null._> (aka field names are as namespaces as values or types)
<discocaml> <contificate> I'm not the most fond of doing that, but it's interesting to know
<discocaml> <._null._> namespaced*
<za3k> yes, i've been having to annotate functions to get patterns to match, I would appreciate being able to move that outside the function signature
<za3k> I agree that syntax is not great
wbooze has joined #ocaml
<za3k> Is there a name for the function that given X, does X.a
<za3k> or do i just have to write a little fun
<discocaml> <._null._> There's no builtin accessor function
<za3k> ok, that's fine, it's still pretty brief
<discocaml> <contificate> you can generate such things with ppx derivers, but that's another topic
<za3k> yeah i tried to keep it simple for this one
wbooze has quit [Remote host closed the connection]
<discocaml> <contificate> do you happen to be Scheme programmer
<za3k> i was, once upon a time
<za3k> i would say these days mostly python and JS
<discocaml> <contificate> I trust you are enjoying OCaml's `match` more than Python's `match` 😏
<za3k> Python has a match?
<za3k> I'd say yes but not as much as Erlang's match
<za3k> Erlang has single static assignment
<za3k> which means you can do things like match 'x' (where x is a constant already defined)
<za3k> or (a, a), meaning a tuple where both values are the same
<za3k> it's pretty wild
<discocaml> <contificate> that's a good practice, things shadow in OCaml for a similar reason
<za3k> that said i've yet to code a single line of erlang
<za3k> yeah you can't have both that and shadowing
<discocaml> <contificate> thing about Python's `match` is that it actually corrupts the environment even if the match fails
<discocaml> <contificate> so you can have no handler executed, but now your environment is broken
<za3k> yikes
<za3k> oh so returning to the previous topic of https://github.com/za3k/text-multiedit/blob/master/client.ml#L41
<za3k> is the reason to prefer 'fun' that it's less characters long
<discocaml> <contificate> you've done it somewhere else as well, where it reads `function |_ -> exit 1`
<discocaml> <contificate> it's no overly important, I just expect cases after `function`
<za3k> do people usually indent the cases or keep them at the same level
<discocaml> <contificate> indented
<discocaml> <contificate> I'd also die on the hill that says you ought to do the same in other languages' `switch` cases 😏
<discocaml> <contificate> otherwise it just looks silly
<discocaml> <contificate> https://github.com/za3k/text-multiedit/blob/master/client.ml#L258C16-L258C53 I'd prefer just `if remote <> [] then` here
wbooze has joined #ocaml
<discocaml> <._null._> As in, the pattern pipes are indented 0-1 times (I'd say 0 iff it makes them aligned with the m of match) and the branches are indented 1-2 times more
<discocaml> <contificate> I wonder if https://github.com/za3k/text-multiedit/blob/master/color.ml#L2-L3 can be done as a kind of modifier, with a map between colours that's consistent and not too broken, I see that most are just `+60` (with some edge cases)
<discocaml> <._null._> (^ opinion, ofc)
<discocaml> <gooby_diatonic> You've moved on, but wanted to say that I used to be against dune before as well but it just makes everything so much easier, while it's not really heavyweight, a few project files and dune files in directories, pretty speedy too
<discocaml> <contificate> I hated dune until I learned more about it for some tricks at work
cbarrett has quit [Ping timeout: 265 seconds]
JSharp has quit [Ping timeout: 245 seconds]
<discocaml> <gooby_diatonic> dynamic_include expert
<discocaml> <contificate> exactly
cbarrett has joined #ocaml
JSharp has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 245 seconds]
<dh`> so far I have seen no reason to adopt dune for my own things
<dh`> like a lot of build tools it's intended for doing simple things automatically, which means it's too canned to handle complex projects
<dh`> and I think we last had this discussion not more than a couple weeks ago ;-)
<companion_cube> It's the opposite, it's designed to scale
<companion_cube> One of the things I'm appreciating more and more is how well vendoring works
Haudegen has joined #ocaml
<dh`> the last big project had a dozen or so interconnected repositories, including multiple tools written in different languages and then a large body of C code (some of it emitted from the tools, some not) that had to be crosscompiled for multiple targets
wbooze has quit [Read error: Connection reset by peer]
<dh`> I think writing the whole of something like that in dune is a nonstarter, and using dune for just the ocaml tools just adds requirements and complexity
<discocaml> <gooby_diatonic> I thinka good thing to keep in mind for perspective is that dune is developed by a huge company which has huge projects and they use and develop dune to handle those projects
<discocaml> <gooby_diatonic> think
<za3k> null, i was indeed asking about the level of indentation of the pipes in pattern match
bibi_ has quit [Ping timeout: 252 seconds]
<companion_cube> If you need to cross compile, I can't speak from experience
<companion_cube> But for large ocaml projects it's really good
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 248 seconds]
bibi_ has joined #ocaml
euphores has quit [Quit: Leaving.]
<discocaml> <contificate> dune is great, can't imagine building the stuff at my work with some other setup
<discocaml> <contificate> cross compilation is an OCaml problem overall, no? like the compiler, once built, is tied to a specific folder and, the `asmcomp` folder just includes arch-specific files during the build, so it's not like you can just say "alright emit me AArch64 now"
<companion_cube> Oh yeah it's a nightmare
rgrinberg has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
euphores has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
Haudegen has joined #ocaml
chrisz has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
hsw_ has joined #ocaml
hsw has quit [Read error: Connection reset by peer]
<dh`> for that project the ocaml stuff was a tool, so it needed to be retargetable but wasn't crosscompiled
<dh`> crosscompiling the C was a shitshow even without trying to do it with not-really-appropriate build tools
<dh`> multiple notions of what a target is and an embedded-world tendency to compile in board-specific stuff on the assumption there's only one board, except that there wasn't
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 265 seconds]
Ekho has quit [Quit: CORE ERROR, SYSTEM HALTED.]
bartholin has quit [Quit: Leaving]
alfiee has joined #ocaml
Ekho has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
bibi_ has quit [Ping timeout: 245 seconds]
Serpent7776 has quit [Ping timeout: 260 seconds]
bibi_ has joined #ocaml
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 260 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 245 seconds]
malte has joined #ocaml
malte has quit [Remote host closed the connection]
malte has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 248 seconds]
mange has joined #ocaml