<dh`>
I'm hoping for something like "use dune, use these five lines of cmake goop to get it to run dune, anything more is somebody else's problem"
<companion_cube>
:/
<companion_cube>
well if you know how to do that…
<dh`>
I don't (also never used dune)
<companion_cube>
well, dune is designed for OCaml, so its little language is well suited for it
<dh`>
my understanding so far is that it's like ocamlbuild but less screwy
<dh`>
that is not a deep understanding :-)
<dh`>
normally I just write makefiles but $WORK currently involves a thing with a gigantic cmake integration
<companion_cube>
makefiles are honestly quite poor for OCaml
<companion_cube>
does cmake have, like, plugins for other languages??
<dh`>
with bsd make it works fine
<companion_cube>
or are C++, etc. directly built-in ?
<dh`>
gmake is annoying but one expects that with gmake
<dh`>
fiik, I assume built in, cmake is not exactly an architected piece of software
<companion_cube>
you still have to screw around with ocamldep and the likes, no? and paths for libraries, etc.
<dh`>
yes but realistically that's a minor problem
<companion_cube>
idk, there's so much stuff to compile
<companion_cube>
I'd be tired
<companion_cube>
what does BSD make provide that gmake doesn't, btw?
<companion_cube>
I'm not too familiar
<dh`>
a real macro language, mostly
<dh`>
so for example you can write SRCS=foo.mli foo.ml bar.mly baz.mll buzz.ml etc and produce all the right rules from that without needing separate lists of mli files or other nuisances
<companion_cube>
oh so you have to list the sources? :s
hornhack has joined #ocaml
rf has quit [Read error: Connection reset by peer]
hackhorn has quit [Read error: Connection reset by peer]
rf has joined #ocaml
<rf>
dh` I think its better to just use dune instead of trying to wire CMake in
<companion_cube>
even producing ninja rules might work better
<companion_cube>
but that's only one target of cmake, I think?
oriba has quit [Ping timeout: 246 seconds]
John_Ivan has quit [Ping timeout: 255 seconds]
bobo_ has joined #ocaml
spip has quit [Ping timeout: 255 seconds]
bobo_ has quit [Ping timeout: 255 seconds]
spip has joined #ocaml
trillion_exabyte has quit [Ping timeout: 246 seconds]
trillion_exabyte has joined #ocaml
chrisz has quit [Ping timeout: 255 seconds]
chrisz has joined #ocaml
waleee has quit [Ping timeout: 246 seconds]
azimut has quit [Ping timeout: 255 seconds]
rf has quit [Quit: Leaving]
<discocaml_>
<Zhou Wu> Fawk.
<discocaml_>
<Zhou Wu> I mean. Gawk.
<discocaml_>
<Zhou Wu> GNU Awk.
mima has quit [Ping timeout: 255 seconds]
trillion_exabyte has quit [Ping timeout: 255 seconds]
trillion_exabyte has joined #ocaml
Haudegen has joined #ocaml
mbuf has joined #ocaml
trev has joined #ocaml
bgs has joined #ocaml
<dh`>
not listing the sources in the makefile (or somewhere) is a liability
<dh`>
having a list that you have to keep in depend order is important for keeping track of the high-level flow of the project
<dh`>
at least for compilers where there is a definite notion of flow like that
<dh`>
also at least with ocamlbuild not listing the files means it has to guess what sources you meant to include in each output
<dh`>
and that doesn't always work out well
<dh`>
rf: unfortunately for this particular thing it has to be wired into the cmake build somehow
bgs has quit [Remote host closed the connection]
bartholin has joined #ocaml
wingsorc has quit [Ping timeout: 248 seconds]
mima has joined #ocaml
bartholin has quit [Remote host closed the connection]
bartholin has joined #ocaml
bartholin has quit [Quit: Leaving]
olle has joined #ocaml
dnh has joined #ocaml
dhil has joined #ocaml
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
hornhack has quit [Ping timeout: 248 seconds]
szkl has joined #ocaml
trillion_exabyte has quit [Ping timeout: 252 seconds]
trillion_exabyte has joined #ocaml
<discocaml_>
<Scarlet> Hey, can anyone help me install Ocaml on VSCode?
<theblatte>
I cannot, but I'm sure others here can and to help them help you it's better to ask your question directly and include context like what problem you are having and what you tried
<discocaml_>
<Scarlet> I have installed ubunto on VirtualBox, i already installed VSCode, im now trying to install the Ocaml , but i have no idea what to do
<technomancy>
so in my repl, I can reference Unix.PF_INET, but trying to refer to Unix.socket or Unix.send gives me "reference to undefined global Unix"; why is it saying it's undefined when clearly it knows what Unix is?
Haudegen has quit [Quit: Bin weg.]
<companion_cube>
oh you need to depend on the unix library
<companion_cube>
(you're probably getting a linking error, when the .cmi files (interface files) were visible)
<companion_cube>
think of it as -I vs -L
<technomancy>
but why can some values be found and others can't?
<technomancy>
and why wouldn't it tell me there's a linking error
<companion_cube>
ohhh in the repl
<companion_cube>
yeah, so: I think it's because PF_INET is a constructor
<companion_cube>
so basically you only need the type definition
<technomancy>
and why would the documentation list Unix under the standard library if it isn't available in the repl?
<companion_cube>
whereas Unix.socket is a function defined somewhere
<companion_cube>
try `#load "unix.cma";;`
<technomancy>
ok, that worked!
<technomancy>
why doesn't the documentation tell you that =\
gwizon has joined #ocaml
<octachron>
Unix is a separate library distributed along the compiler and the standard library
<octachron>
Unfortunately, for a long time, the interface file of the unix library where mixed with the one of the standard library
<octachron>
This is no longer the case in 5.0, but there is a temporary compatibility mode that emits an alert but still let you access the Unix interfaces.
<technomancy>
OK, I'm on debian, so it's giving me 4.11
<technomancy>
is there some documentation I can read about how to make the repl work?
<octachron>
Use utop? (or maybe down)
<technomancy>
ok, I'll try that
<octachron>
Also the OCaml packages distributed by your distribution generally ends up being impractical at some point.
<technomancy>
well, my purpose is to just port a 100-line example program for pedagogical purposes
<octachron>
And once you switch to opam, there are few reasons to use the OCaml distributed by your distribution.
<technomancy>
using non-distro packages would be counter-productive for my purposes
<octachron>
In that case, it does sound like the shortest path is probably the best path indeed.
<technomancy>
I'm trying to minimize the number of weird gotchas that can only be discovered by asking about them on chat because the official docs don't explain it, but it does seem like "use utop instead of the stock repl" is worth it
<technomancy>
utop appears to be attempting to do some weird curses-powered completion even tho it's not actually running in a terminal
<technomancy>
but at least it can find standard library stuff, haha
<technomancy>
back when I tried ocaml like seven years ago or whatever I was using the jane street stuff to convert records to sexp and print the sexp
<technomancy>
is there a way to do that without 3rd-party libraries that's been added since then?
<discocaml_>
<geoff> ppx derivers are the way to do that still
<discocaml_>
<geoff> janestreet just happens to write a lot of ppxs
bartholin has joined #ocaml
<technomancy>
so when I go and run a program that uses the stdlib, I still have to specify the cma files of what I'm using even tho they're supposedly built-in?
<technomancy>
is there a good overview in the documentation of how this works?
<technomancy>
what on earth does this mean? Exception: Unix.Unix_error(Unix.EINVAL, "socket", "")
<companion_cube>
it's the EINVAL C error?
<companion_cube>
what did you do :p
<technomancy>
let srv = Unix.socket Unix.PF_INET Unix.SOCK_STREAM port
<companion_cube>
ah
<technomancy>
I'm assuming that's the line that triggered it; just a guess since there's no line number
<companion_cube>
it's not a port number, use 0
<technomancy>
...?
<Fardale>
technomancy: no, to run program you don't need to give anything
<companion_cube>
also: `OCAMLRUNPARAM=b the_program` (but you use the repl I guess)
<companion_cube>
Unix.socket doesn't take a port number, it takes 0
<companion_cube>
and then you can bind a addr+port, or connect
<reynir>
man socket
<technomancy>
the man page says "Create a new socket in the given domain, and with the given kind. The third argument is the protocol type" but I guess it's actually saying the fourth argument?
<companion_cube>
[…] 0 selects the default protocol for
<companion_cube>
that kind of sockets.
<technomancy>
ok, so the man page lists 3 arguments before that
<technomancy>
but I guess the first one ... doesn't count?
<companion_cube>
idk what the protocol type is otherwise. Ports belong in `Unix.sockaddr`
<companion_cube>
the optional doesn't count indeed
<companion_cube>
(it was probably added later, too)
<technomancy>
ok, thanks
<technomancy>
companion_cube: is OCAMLRUNPARAM=b better than running `ocaml unix.ma myfile.ml`? the tutorials don't really explain this
<technomancy>
I guess they want to push you to a full-fledged build tool right out of the box, but that doesn't really fit with what I'm trying to do
dhil has joined #ocaml
<technomancy>
oh, no ok OCAMLRUNPARAM a completely different thing; sounds like you were answering a different question
<technomancy>
OCAMLRUNPARAM=b gives me a stack trace, but it's just "unknown location" over and over
<discocaml_>
<peval> using the bytecode interpreter and repl like that you can put: `#use "topfind"` then `#require "unix"` at the top
<discocaml_>
<peval> otherwise you use ocamlfind to compile if you don't want to use a build system
<discocaml_>
<peval> like `ocamlfind ocamlc -linkpkg -package unix myfile.ml`
<companion_cube>
technomancy: it just prints backtraces
<companion_cube>
and yeah, bytecode sucks
<technomancy>
anyway, I got my socket open; progress!
Tuplanolla has joined #ocaml
<technomancy>
sooooo I guess the Unix stuff is all going to use exceptions instead of Options?
<companion_cube>
yep
<technomancy>
guess that's what I get when I stick with built-in stuff instead of 3rd-party libraries
<technomancy>
for this particular pain, I can accept the fact that I brought it on myself =)
<technomancy>
*every* language has their old embarrassing APIs from back when before they knew better
<companion_cube>
tbh I wouldn't love it if all of Unix used `result`
<companion_cube>
it's a massive pain to check every single return
<technomancy>
hm; ok, so exceptions are actually not that different from options after all, for my purposes here
<technomancy>
I mean, provided you catch them immediately and don't let them propagate
<companion_cube>
sure
<technomancy>
cool
<discocaml_>
<peval> they're very efficient in ocaml too as opposed to most other languages
jaycle has joined #ocaml
<technomancy>
ok this was a really rough start but it's coming together =)
jaycle has quit [Client Quit]
<discocaml_>
<masterbuilder> really?
<discocaml_>
<masterbuilder> so using them for control flow is not a huge performance killer?
<companion_cube>
no
<companion_cube>
especially not if you use `raise_notrace`
<discocaml_>
<masterbuilder> I don't really like non-exceptional exceptions though to be honest
<companion_cube>
and within a single function, if the exception doesn't escape, it's basically a goto
<discocaml_>
<masterbuilder> aha, I see
<technomancy>
ohhh it looks like I should be using Unix.establish_server instead of creating the sockets manually, because the latter forces you to wrangle byte buffers directly?
<technomancy>
oh wait, no. establish_server forks a separate process; that's not going to work.
<technomancy>
time to learn about bytes
<companion_cube>
let b = Bytes.create 256 in … input b off len …
<technomancy>
args for recv aren't actually documented =(
<octachron>
You can use `UnixLabels` to avoid int blindness in this case
<octachron>
val recv : UnixLabels.file_descr -> buf:bytes -> pos:int -> len:int -> mode:UnixLabels.msg_flag list -> int
<technomancy>
oh; that's way better
<technomancy>
why is the unlabeled one the default?
<companion_cube>
because it predates labels :D
<technomancy>
ouch
<technomancy>
but ... why not explain the arguments in the regular Unix module documentation?
<companion_cube>
ooof, yeah :D
<companion_cube>
it's like "it's just like C, yolo"
<companion_cube>
(after a while you actually get used to `bytes -> int -> int -> int` tbh)
<companion_cube>
(gives a slice, get back how many bytes were read)
<technomancy>
yeah, that's what I thought at first too
<technomancy>
but it's not
<technomancy>
the C one only takes one int instead of two
<companion_cube>
because of pointer arith
<technomancy>
sure, but that's one of those questions whose answer is only obvious once you know it
<companion_cube>
yeah
<technomancy>
anyway just some thoughts for next time someone asks "why isn't ocaml more popular?" =)
<companion_cube>
🤷
alexherbo2 has joined #ocaml
technomancy[m] has joined #ocaml
Serpent7776 has joined #ocaml
trev has quit [Remote host closed the connection]
<technomancy>
https://p.hagelb.org/read-line.html so it looks like with Unix's sockets I'm on my own and have to implement read_line myself; does this look correct?
wingsorc has joined #ocaml
<companion_cube>
you can use `Unix.in_channel_of_descr`
<companion_cube>
and use the higher level API
<companion_cube>
like `input_line`
<technomancy>
it says text mode is not supported on sockets
<companion_cube>
wait, does it fail?
<technomancy>
well, I didn't try it because the man page told me not to =)
<companion_cube>
you can read lines without the so called "text mode"
<companion_cube>
(which is, btw, a misfeature)
<technomancy>
oh wait what?
<companion_cube>
(text mode = on windows, it'll try and turn \n to \r\n or sth like that, yikes)
<technomancy>
oh god, lmao
<technomancy>
so "binary" mode will still give me a string?
<companion_cube>
yep
<technomancy>
how does anyone use this documentation without joining chat to find out where the docs are wrong? =)
<discocaml_>
<NULL> Do that many people use `Unix` ?
<companion_cube>
idk who uses Unix as the first thing, technomancy
<companion_cube>
I mean, I do use it, but it's not the friendliest part of OCaml 😂
bgs has quit [Remote host closed the connection]
dhil has quit [Ping timeout: 255 seconds]
<adrien>
what's that website already? not rosettacode but another one with implementations for a number of tasks in a number of languages?
<technomancy>
is it normal to put the #load in the source?
<adrien>
it's fairly "old"; I think most of the code was contributed more than ten years ago
<adrien>
#load is only for the REPL
<technomancy>
so the examples there are meant to be pasted in the repl then
<adrien>
you can #use "somefile.ml" (or execute from emacs?) but apart from that, you shouldn't use it
<technomancy>
huh, well, it appears not; some of these have like ... a shebang, but also #load
<technomancy>
so maybe this site isn't super trustworthy =\
<adrien>
but I guess the shebang is from "ocaml", right?
<adrien>
so that's consistent
<technomancy>
I don't understand
<adrien>
ocaml is the REPL; you can invoke it as "ocaml" but also as "ocaml somefile.ml", just like you'd do with bash
<technomancy>
ok so I guess "repl" means something very different here
<technomancy>
you're saying you would use that word even for non-interactive uses?
<adrien>
hmm, you're right, that's not very clear
<companion_cube>
kind of weird, yeah, but indeed `ocaml foo.ml` will feed the code to ocaml as if it were a repl
<companion_cube>
most people tend to compile the code
<adrien>
"ocaml somefile.ml" works almost as if you copy-pasted the content of the file into "ocaml"
<technomancy>
and there are meaningful semantic differences with that, it sounds like?
<adrien>
the main difference is that lines which start with '#' are instructions for the toplevel (save for the shebang)
<technomancy>
cool, so like ... little directives that wouldn't be necessary in AOT context because then they would be part of the build script?
<adrien>
yes, typically
<adrien>
you can enter "#help;;" to get the list
<companion_cube>
well, #load and all that will work, yeah
<companion_cube>
in compilation mode they don't
<adrien>
you can also act on the pretty-printer and query types
<technomancy>
https://v2.ocaml.org/api/In_channel.html this claims input_line returns a string option but my repl says it returns "item"; did that change in 4.x -> 5.x?
<adrien>
# input_line;;
<adrien>
- : in_channel -> string = <fun>
<adrien>
so, yes
<technomancy>
ok, found it in the man page. why does the man page say `string` but the repl says `item`?
<adrien>
not sure about "item", that makes me wonder if you have a specific setup, maybe auto-loaded libraries
<adrien>
I really don't know what would use "item" here tbh
<technomancy>
restarted my repl and it's back to string! that's weird but ... I'll just pretend I didn't see that for now.
<adrien>
I need to have some sleep, good night
<technomancy>
thanks for your help =)
<technomancy>
sorry to flood with so many questions
<technomancy>
threads... now that would be a whole different course =)
<companion_cube>
what do you use in fennel for that, btw? :)
<companion_cube>
is it some basic IO library?
<technomancy>
luasocket; it's also a thin wrapper around posix sockets, but slightly less low-level
<companion_cube>
ah yeah
<companion_cube>
I need to warm up to lua, now that I use it for neovim
<technomancy>
like you can create a socket, bind, and listen all in one function call; such luxury =D
<companion_cube>
:DDD
<technomancy>
doing this in lua without pattern matching kinda sucks
<companion_cube>
alright, afk
<technomancy>
but it makes a sweet compilation target
<technomancy>
companion_cube: ttyl; thanks for your help!
olle has quit [Ping timeout: 248 seconds]
<technomancy>
huh... apparently I have no choice; even if you set timeouts, trying to input_line on one of these sockets raises Sys_blocked_io
<technomancy>
so what's the point of having timeouts then? ಠ_ಠ
<discocaml_>
<NULL> à²_ಠ? What kind of smiley is that ?
<companion_cube>
Is teal a real thing now?
<companion_cube>
(on my phone, lolol)
<companion_cube>
technomancy: might be tcp timeouts perhaps?? Idk
<technomancy>
companion_cube: teal ... is a thing that exists
<technomancy>
but the type system is ... not good
<technomancy>
the FAQ is like "Q: what do you do about nils? A: well, nils are hard. so we don't do anything with them yet. everything is nilable."
<companion_cube>
Heh
<technomancy>
(I stopped reading at that point, because why bother if you're not going to actually try to solve the hard problem)
<technomancy>
I have a suspicion that the only viable way to do that is using success typing a la dialyzer, but I haven't really been able to give that the attention I'd like
<companion_cube>
Hmmm. Idk, it can still be somewhat useful. But maybe idioms are too dynamic anyway
<technomancy>
Lua uses a lot of nils, everywhere
<technomancy>
but it's slightly less bad than Clojure, because nils are consistently used as a "not found" value, instead of "sometimes it's not found, sometimes it's false, sometimes it's the empty list, sometimes it means something else; idk"
<technomancy>
like there's no difference between setting a key to nil vs removing it from the data structure, which is really nice, if you are stuck with nils
waleee has quit [Ping timeout: 252 seconds]
bartholin has quit [Quit: Leaving]
<technomancy>
ok so. if I leave off the timeout on the server socket, then I can't accept because it blocks the main thread forever. if I set the timeout, then I can accept, but I can't read from the clients because it raises Sys_blocked_io.
<technomancy>
the docs claim that I can turn the timeout off with a 0, but if I try to do that before reading (and turn it back on afterwards) it has no effect
<discocaml_>
<darrenldl> i might have missed it - is your code online?
<discocaml_>
<darrenldl> i recall mangling with unix sockets being quite messy even in python, and students often got lost
waleee has joined #ocaml
<companion_cube>
I've always used threads with sockets (or lwt), so I can't help much