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/
rgrinberg has quit [Quit: Textual IRC Client: www.textualapp.com]
rgrinberg has joined #ocaml
Inline has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
dukester has joined #ocaml
alfiee has joined #ocaml
<dukester> noob here again! Problem: using begin...end in if conditionals. I keep getting an error using begin..end in the else clause only. see https://controlc.com/33de8fd4
<dukester> ocamlc -o sandbox sandbox.ml File "sandbox.ml", line 5, characters 0-4: 5 | else begin ^^^^Error: Syntax error
alfiee has quit [Ping timeout: 244 seconds]
pi3ce has joined #ocaml
<discocaml> <uberpyro181> There's an extraneous `;;` before `else`. You only need `;;` to end definitions in utop.
<discocaml> <uberpyro181> (Or to improve error messages between let definitions)
<discocaml> <uberpyro181> (Or to improve error messages between definitions)
<dukester> I'm not in utop. I compiled the snippet and ran it
<discocaml> <uberpyro181> ```ocaml
<discocaml> <uberpyro181> let number: int = 10;;
<discocaml> <uberpyro181>
<discocaml> <uberpyro181> if number > 0 then
<discocaml> <uberpyro181> print_string "Number is Positive\n";;
<discocaml> <uberpyro181> else begin
<discocaml> <uberpyro181> print_string "In the else clause ...";
<discocaml> <uberpyro181> print_string "Number is Negative\n";
<discocaml> <uberpyro181> end
<discocaml> <uberpyro181> ```
<discocaml> <uberpyro181> vvv
<discocaml> <uberpyro181> ```ocaml
<discocaml> <uberpyro181> let number: int = 10
<discocaml> <uberpyro181>
<discocaml> <uberpyro181> if number > 0 then
<discocaml> <uberpyro181> print_string "Number is Positive\n";;
<discocaml> <uberpyro181> else begin
<discocaml> <uberpyro181> print_string "In the else clause ...";
<discocaml> <uberpyro181> print_string "Number is Negative\n";
<discocaml> <uberpyro181> end
<discocaml> <uberpyro181> ```
<discocaml> <uberpyro181> sorry i forgot to make the change
<discocaml> <uberpyro181> ```ocaml
<discocaml> <uberpyro181> let number: int = 10;;
<discocaml> <uberpyro181>
<discocaml> <uberpyro181> if number > 0 then
<discocaml> <uberpyro181> print_string "Number is Positive\n";;
<discocaml> <uberpyro181> else begin
<discocaml> <uberpyro181> print_string "In the else clause ...";
<discocaml> <uberpyro181> print_string "Number is Negative\n";
<discocaml> <uberpyro181> end
<discocaml> <uberpyro181> ```
<discocaml> <uberpyro181> vvv
<discocaml> <uberpyro181> ```ocaml
<discocaml> <uberpyro181> let number: int = 10;;
<discocaml> <uberpyro181>
<discocaml> <uberpyro181> if number > 0 then
<discocaml> <uberpyro181> print_string "Number is Positive\n"
<discocaml> <uberpyro181> else begin
<discocaml> <uberpyro181> print_string "In the else clause ...";
<discocaml> <uberpyro181> print_string "Number is Negative\n";
<discocaml> <uberpyro181> end
<discocaml> <uberpyro181> ```
<discocaml> <uberpyro181> There
<dukester> Got it! LOL
<dukester> Thx I'll give a go ..
<dukester> Gotta remember the single semi-colon!!
<discocaml> <uberpyro181> yes, or you can leave it off
<dukester> right on ...
<dukester> thx
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<dukester> discocaml: I just discovered that compilation fails if I omit the semi-colon after the last 2 print statements.
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 252 seconds]
<discocaml> <Kali> discocaml is the name of the irc<->discord bridge
<dukester> kali: thx
<dukester> uberpyro181: I just discovered that compilation fails if I omit the semi-colon after the last 2 print statements.
<discocaml> <Kali> you can only omit it for the second one
<dukester> Got it! Thx ...
<discocaml> <Kali> `;` is like an operator where `expr1 ; expr2` runs expr1 and then expr2 and returns the result of expr2
<discocaml> <Kali> i say "like" and not "is" because it is not actually an operator, just syntax (otherwise you would not be able to have trailing semicolons)
<dukester> It'll become clear the more I mess with some code. Thx again ...
dukester has left #ocaml [Time to go]
<discocaml> <uberpyro181> In the general case, the final expression is a value
<discocaml> <uberpyro181> so in more typical ocaml code, there's some number of effects, and then some value at the end
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 265 seconds]
Tuplanolla has quit [Quit: Leaving.]
hsw has quit [Remote host closed the connection]
hsw has joined #ocaml
Johann has quit [Server closed connection]
Johann has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
myrkraverk has joined #ocaml
myrkraverk_ has quit [Ping timeout: 244 seconds]
ygrek has quit [Remote host closed the connection]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 248 seconds]
Haudegen has joined #ocaml
myrkraverk_ has joined #ocaml
ygrek has joined #ocaml
myrkraverk has quit [Ping timeout: 272 seconds]
terrorjack45 has quit [Quit: The Lounge - https://thelounge.chat]
ggb has quit [Server closed connection]
ggb has joined #ocaml
terrorjack45 has joined #ocaml
rustyne has quit [Server closed connection]
rustyne has joined #ocaml
alfiee has joined #ocaml
_alix has quit [Server closed connection]
_alix has joined #ocaml
alfiee has quit [Ping timeout: 246 seconds]
xvilka has quit [Server closed connection]
xvilka has joined #ocaml
whereiseveryone has quit [Server closed connection]
whereiseveryone has joined #ocaml
ygrek has quit [Remote host closed the connection]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 260 seconds]
sleepydog has quit [Server closed connection]
sleepydog has joined #ocaml
ursa-major has quit [Server closed connection]
ursa-major has joined #ocaml
i` has joined #ocaml
i` has quit [Client Quit]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 272 seconds]
myrkraverk_ has quit [Ping timeout: 252 seconds]
y331 has joined #ocaml
jyc has quit [Server closed connection]
jyc has joined #ocaml
mbuf has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
cbarrett has quit [Server closed connection]
cbarrett has joined #ocaml
welterde has quit [Server closed connection]
welterde has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 272 seconds]
qesat60 has quit [Server closed connection]
qesat60 has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
Serpent7776 has joined #ocaml
pi3ce has quit [Ping timeout: 252 seconds]
alfiee has joined #ocaml
bacam has quit [Server closed connection]
bacam has joined #ocaml
alfiee has quit [Ping timeout: 276 seconds]
Serpent7776 has quit [Ping timeout: 244 seconds]
rgrinberg has joined #ocaml
bartholin has joined #ocaml
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
olle has joined #ocaml
<discocaml> <holmdunc> That's why I like to format it with a space before the semicolon. I'm glad `ocamlformat` supports that style (`--sequence-style separator`)
Tuplanolla has joined #ocaml
pippijn has quit [Ping timeout: 246 seconds]
rgrinberg has joined #ocaml
pippijn has joined #ocaml
haesbaert has quit [Remote host closed the connection]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
oisota has quit [Server closed connection]
oisota has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
rynite has joined #ocaml
keyboard has quit [Server closed connection]
keyboard has joined #ocaml
Serpent7776 has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 272 seconds]
y331 has quit [Ping timeout: 252 seconds]
infinity0 has quit [Server closed connection]
infinity0 has joined #ocaml
myrkraverk has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 276 seconds]
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 248 seconds]
mbuf has quit [Quit: Leaving]
rynite has quit [Read error: Connection reset by peer]
rynite has joined #ocaml
rynite has quit [Quit: WeeChat 4.4.1]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 246 seconds]
pi3ce has joined #ocaml
olle has quit [Ping timeout: 252 seconds]
pi3ce has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
myrkraverk has joined #ocaml
myrkraverk_ has quit [Ping timeout: 276 seconds]
ygrek has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
ygrek has quit [Remote host closed the connection]
rgrinberg has joined #ocaml
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 244 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 265 seconds]
Haudegen has quit [Quit: No Ping reply in 180 seconds.]
Haudegen has joined #ocaml
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
Haudegen has quit [Quit: No Ping reply in 180 seconds.]
Haudegen has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
ygrek has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
rgrinberg has joined #ocaml
ansiwen has quit [Quit: ZNC 1.7.1 - https://znc.in]
alexherbo2 has joined #ocaml
rgrinberg has quit [Read error: Connection reset by peer]
rgrinberg has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 246 seconds]
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
Haudegen has quit [Read error: Connection reset by peer]
Haudegen has joined #ocaml
bibi_ has quit [Quit: Konversation terminated!]
bibi_ has joined #ocaml
haesbaert has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 248 seconds]
dukester has joined #ocaml
<dukester> Introduction to Objective Caml by Jason Hickey Chapter 2.2.5 states: "the expression s.[i] <- c replaces the i’th in string s by character c, returning a unit value.
<dukester> # "Hello".[0] <- 'h';;
<dukester> Hint: Mutable sequences of bytes are available in the Bytes module.
<dukester> Error: Syntax error: strings are immutable, there is no assignment syntax for them.
<dukester> Hint: Did you mean to use Bytes.set?
<dukester> Is that book out-of-date?
<discocaml> <Kali> yes
<dukester> Just my bloody luck! OK thx
<discocaml> <yawaramin> the name 'Objective Caml' was officially changed to 'OCaml' back in 2011. so it's out of date by about 14 years
<dukester> Got it! Hickey's book is still around though confusing noobs like me.
<discocaml> <yawaramin> where did you find it? Google?
<dukester> Can't remember! I DLed it to study off-line.
<discocaml> <Kali> mutable strings have not existed in ocaml since 4.10, which came out 5 years ago
<discocaml> <Kali> at least, not by default
<discocaml> <Kali> you can still force it with a flag, i think
<discocaml> <yawaramin> not any more, looks like: `.../bin/ocaml: OCaml has been configured with -force-safe-string: -unsafe-string is not available.`
alfiee has joined #ocaml
Inline has quit [Ping timeout: 244 seconds]
alfiee has quit [Ping timeout: 248 seconds]
myrkraverk has joined #ocaml
myrkraverk_ has quit [Ping timeout: 252 seconds]
<dukester> The "else" branch may be omitted in an "if" conditional. So the following throws an error: if 1 < 3 then 1 ! How do you get around that if you don't want an "else"?
germ has quit [Read error: Connection reset by peer]
<discocaml> <._null._> You can only forego an else if the then only has side-effects (ie. returns unit)
<discocaml> <._null._> What would `let n = if false then 1 in ...` mean otherwise ?
<dukester> OK thx ... That bloody book didn't say that.
germ has joined #ocaml
dukester has left #ocaml [Time to go]
<discocaml> <yawaramin> the Hickey book? http://courses.cms.caltech.edu/cs134/cs134b/book.pdf
<discocaml> <yawaramin> > the else branch is not required in a conditional. If it is omitted, the conditional is treated as if the else case returns the () value.
<discocaml> <alyxshang> Will this work for user-defined types too? How is this constrained?
<discocaml> <alyxshang>
<discocaml> <alyxshang> ```OCaml
<discocaml> <alyxshang> let is_equal_to (a: 'a) (b: 'a) : bool =
<discocaml> <alyxshang> a == b
<discocaml> <alyxshang> ```
<discocaml> <yawaramin> `==` is doing reference ie pointer equality, it is checking whether `a` and `b` point to the same location in memory
<discocaml> <yawaramin> you almost always want `=` instead
<discocaml> <alyxshang> And that'll work for user-defined types?
<discocaml> <alyxshang> In Shangshield I do want that, don't get me wrong.
<discocaml> <yawaramin> for user-defined types things get more complex. the built-in `=` is not guaranteed to work for all possible types, eg if a type contains a function it will throw an exception at runtime. usually for custom types a custom equality function is provided
<discocaml> <alyxshang> What would you recommend?
<discocaml> <alyxshang> Or how would I make that possible?
<discocaml> <yawaramin> simplest way is to pass in the equality or comparison function eg see https://ocaml.org/manual/5.3/api/List.html#VALcompare
<dh`> = is defined on everything but it doesn't _work_ on everything
* discocaml <alyxshang> horrified noises
<dh`> it was an expedient alternative to having typeclasses
<discocaml> <alyxshang> It is what it is. 🤷‍♀️
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 252 seconds]
infinity0 has quit [Ping timeout: 252 seconds]
Inline has joined #ocaml
alexherbo2 has quit [Remote host closed the connection]
myrkraverk has quit [Ping timeout: 252 seconds]
myrkraverk has joined #ocaml
infinity0 has joined #ocaml
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 272 seconds]
dukester has joined #ocaml
<dukester> I installed OCAML with the following bash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)"
<dukester> opam init
<dukester> eval $(opam env --switch=default)
<dukester> 346 opam install ocaml-lsp-server odoc ocamlformat utop
<dukester> How do I uninstall it?
rgrinberg has joined #ocaml
<discocaml> <chrisarmstrong> ‘opam env’ will tell you where the switch is installed, probably $HOME/.opam/default
<discocaml> <chrisarmstrong> The opam binary itself, Im not sure
<dukester> Yes - that's where all the OCAML stuff lives
<dukester> so do I simply nuke the .opam directory?
<discocaml> <Kali> and remove any hooks added to your shell profile if it added some
<dukester> right on thx
<discocaml> <chrisarmstrong> Yes; nothing is added outside of it except for the opam binary (which is self contained and can just be removed as is) and the shell hooks as Kali mentioned
<dukester> shell hooks being all the env. vars that were set?
<dukester> Too bad that there isn't an opam uninstall command though!
alfiee has joined #ocaml
<discocaml> <chrisarmstrong> No your shell configuration (eg .bashrc) will have been updated
<discocaml> <chrisarmstrong> The environment variables are set by the eval $(opam env) command
<dukester> so remove anything in .bashrc that pertains to ocaml/opam?
alfiee has quit [Ping timeout: 252 seconds]
<discocaml> <yawaramin> the opam tool is supposed to be installed by some other package manager, so you would use that to uninstall it
<discocaml> <._null._> Unless you're really bothered by two lines, they won't do anything if the script they want to run isn't present, so if you deleted `.opam` it won't find anything
<discocaml> <yawaramin> eg brew, apt, WinGet etc.
<discocaml> <._null._> (The package manager won't touch .opam or .bashrc though)
<dukester> The version of ocaml in DEbian is old. I installed the latest
<dukester> I installed with: bash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)"
<discocaml> <._null._> You'll probably have to rm /usr/local/bin/opam then
<dukester> you bet!
<discocaml> <yawaramin> but yeah, the installer script should probably also add an uninstall command. that's a good issue to file imho
<dukester> I agree - but not this noob. Somebody with a track record should though!!
<discocaml> <._null._> Don't overestimate what it takes to file an issue
<discocaml> <yawaramin> and in my experience maintainers don't look at track record, they just care about if a good justification is given for the issue
<dukester> LOL - I'l keep plugging away with OCAML - maybe watching Clarkson videos. First crack with functional/ml langs.
<discocaml> <yawaramin> depending on your programming experience maybe we can recommend something
<dukester> Mostly Perl/C/some LISP - all hobbyist/amateur
Serpent7776 has quit [Ping timeout: 252 seconds]
alfiee has joined #ocaml
alfiee has quit [Ping timeout: 244 seconds]
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
rgrinberg has joined #ocaml
<discocaml> <yawaramin> with the caveat that nothing might be the perfect fit: check out https://johnwhitington.net/ocamlfromtheverybeginning/index.html , https://ocaml.github.io/ocamlunix/ocamlunix.html , and https://dev.realworldocaml.org/toc.html (but leave this one for last)
<discocaml> <27theo> Is it possible to watch for changes to a table in a PostgreSQL database with Caqti? I've not been using it for long, so my understanding of the library is very limited
<dukester> @yawaramin thx a bunch ...
bartholin has quit [Quit: Leaving]
<discocaml> <27theo> Thank you! I see that it is possible with postgresql-ocaml, I suppose I'll have to make the switch