Frostillicus has quit [Read error: Connection reset by peer]
Frostillicus has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
Tuplanolla has quit [Quit: Leaving.]
humasect has joined #ocaml
Frostillicus has quit [Ping timeout: 248 seconds]
Frostillicus has joined #ocaml
<discocaml>
<contificate> > wasn't it you I got into a huge fight with over parsing? if not, I apologize
<discocaml>
<contificate> I don't recall a fight - but we do disagree about precedence declaration usage with LR parser generators 😉
<discocaml>
<contificate> an underrated feature of monadic parser combinators - as was alluded to by ccube (when he mentioned parsing network protocols) - is their monadic nature (read: being in CPS) makes it easy to do buffered parsing (as in` Angstrom.Buffered`)
<discocaml>
<contificate> it's nice being able to implicitly create a state machine from a parser so that async read callbacks can just parse whenever they have enough
<companion_cube>
or, you can use direct style and effects to refill the buffer :p
<discocaml>
<contificate> what you find in handwritten C code is basically state machines a-la defunctionalisation of the monadic version - see any open source websocket protocol parser, it maintains partial state ("how much of the header have we seen?") - that "how much have we parsed so far" is just the free variables of continuation closures in monadic style
<companion_cube>
I'm just very excited for await+lwt :3
<discocaml>
<yawaramin> companion_cube: CBOR parser takes a binary as input, right? do you have a recursive-descent parser that takes a human-readable string handy? like say a Thrift IDL parser
<companion_cube>
using parser combinators, not that I'm super fond
<discocaml>
<yawaramin> right, i am looking for specifically a recursive descent parser like the one dh is talking about to compare to a parser combinator approach
<discocaml>
<contificate> almost discussing misnomers here as people routinely implement recursive descent using parser combinators - we're saying "recursive descent" as meaning direct style
<discocaml>
<yawaramin> yeah i understand the terminology is kinda not great because parser combinators are recursive descent. i really mean hand-written recursive descent parser like the ones dh is talking about
<discocaml>
<yawaramin> as opposed to using a combinator library
<companion_cube>
it's kind of hard, in OCaml, to resist writing any kind of combinator 😅
<discocaml>
<contificate> yeah, I write a lot of `(Token.t -> 'a option) -> 'a` things
<discocaml>
<contificate> unrelated but it makes me want to design an ML with first class tags
<discocaml>
<contificate> I often write like `expect ((=) Token.EOF)`, but you can only do that for nullary constructors
<companion_cube>
I'd rather have a `matches!` construct
<discocaml>
<contificate> I think Jane Street has a ppx rewriter that gives you that, in effect
<discocaml>
<contificate> in that it'll generate predicates modulo payload, `is_a_foo = function Foo _ -> true > _ -> false`
<discocaml>
<contificate> oh I've got an American keyboard layout, great
Frostillicus has quit [Read error: Connection reset by peer]
Frostillicus has joined #ocaml
humasect has quit [Quit: Leaving...]
Frostillicus has quit [Ping timeout: 276 seconds]
Frostillicus has joined #ocaml
toastal has joined #ocaml
<dh`>
handwritten C code for protocols is often push-style (where you maintain an explicit state machine) because it's convenient to plug it into multiple sockets and a select loop that way
<dh`>
but there's also plenty of handwritten C code that's pull-style
<dh`>
(yacc generates pull-style code, which is really bloody annoying at times)
<dh`>
anyway, I have a recursive descent non-combinator C parser if anyone wants to look at it, but it's not small
<discocaml>
<contificate> > because it's convenient to plug it into multiple sockets and a select loop that way
<discocaml>
<contificate> yeah, that's what I'm saying: with combinators, you can just capture the continuation and derive a state machine - `start : 'a t -> 'a state`, `feed : 'a state -> input -> 'a state` - so you can just attach it to an async callback and incrementally parse when you have enough bytes without explicitly maintaining a state machine
<discocaml>
<contificate> doing the same in C can be error-prone and amounts to a kind of mechanical process ("mechanical" in that you could defunctionalise the monadic verison and get almost the same idea)
<dh`>
right, there are lots of ways to convert push to pull
<dh`>
except C doesn't have any of them
<dh`>
it is entirely mechanical in the sense you can write it as a formal translation step
<dh`>
the best solution in C code is to just fork and feed the data across a pipe
<discocaml>
<contificate> you're reminding me of one of the neatest things I learned when I was doing some basic systems programming at my old job: SCM_RIGHTS
<dh`>
there have been many exciting system-level problems caused by that facility :-)
<dh`>
one of the fun ones: take a socket, send it down itself, then close it
<companion_cube>
What is that?
<discocaml>
<contificate> can transfer file descriptors across processes
<discocaml>
<contificate> so you can be like "alright our ability to handle lots of connections sucks" or "maybe we should support some other protocol" etc.
<discocaml>
<contificate> then just write that in well supported Go and pass the fd onto OCaml when done
<discocaml>
<contificate> across processes without inheritance I'd add
<dh`>
yeah, file descriptor passing over local sockets
<discocaml>
<contificate> at my old job, there were some problems with contention - the OCaml was just a simple webserver and it'd spawn a Thread.t per connection, meaning you could easily create hundreds of pthreads in the space of a few seconds, then starve important threads (because you may timeslice a bunch of new threads before a critical thread releases a lock)
<discocaml>
<contificate> I think they're using cgroups and modifying timeslice to fix it now, but my idea was to basically shard part of the service to have a better load balancing frontend to handle trivial requests
<discocaml>
<contificate> and part of that would've been forwarding the socket to the real process for important things
<discocaml>
<contificate> was just a theoretical thing, but I remember being like "oh, you can just do that? neat"
<dh`>
it's not "just" ;-)
<dh`>
but yeah, it's nice to be able to do
<dh`>
my vague recollection is that because it's part of sockets it only worked on BSD unixes
<dh`>
I can't remember if svr4 tried to add its own mechanism that didn't work or if I'm thinking of something else
<dh`>
"svr4 added new stuff that didn't work" doesn't exactly narrow it down
<discocaml>
<yawaramin> there must be one out there written in OCaml even for a toy language like a simple arithmetic for demo purposes
<discocaml>
<contificate> there must be a what? I linked a direct style recursive descent parser for Myte above
<discocaml>
<yawaramin> right, thanks, it's a full-fledged programming language so a lot to take in 🙂
<discocaml>
<contificate> a lot of handwritten parsers will be recursive descent generally, but then use Pratt parsing for expressions
<discocaml>
<contificate> where "Pratt parsing" is known by 4-5 other names
<discocaml>
<yawaramin> like i'm looking for something that's preferably a single file that i can just load in my REPL and play around with, check the outputs, errors, etc.
<discocaml>
<contificate> why? just intrigue?
<discocaml>
<yawaramin> to learn
Frostillicus has quit [Read error: Connection reset by peer]
Frostillicus has joined #ocaml
casastorta has quit [Ping timeout: 252 seconds]
tronexte has quit [Ping timeout: 260 seconds]
Frostillicus has quit [Ping timeout: 252 seconds]
casastortaAway has quit [Quit: ZNC 1.10.1 - https://znc.in]
casastorta has joined #ocaml
casastortaAway has joined #ocaml
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 265 seconds]
amadaluzia has joined #ocaml
amadaluzia has quit [Client Quit]
myrkraverk has joined #ocaml
myrkraverk_ has quit [Ping timeout: 252 seconds]
Frostillicus has joined #ocaml
casastorta has quit [Ping timeout: 252 seconds]
myrkraverk_ has joined #ocaml
casastorta has joined #ocaml
myrkraverk has quit [Ping timeout: 276 seconds]
myrkraverk has joined #ocaml
myrkraverk_ has quit [Ping timeout: 276 seconds]
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 265 seconds]
myrkraverk has joined #ocaml
<dh`>
I started writing one because I wasn't about to get anything else done on sunday night, but it got slightly out of hand
myrkraverk_ has quit [Ping timeout: 248 seconds]
<dh`>
also, if it's simple it ends up not that interesting from a language standpoint
<dh`>
er, a parsing standpoint
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 260 seconds]
toastal has left #ocaml [#ocaml]
Frostillicus has quit [Ping timeout: 252 seconds]
myrkraverk has joined #ocaml
myrkraverk_ has quit [Ping timeout: 252 seconds]
Frostillicus has joined #ocaml
germ_ has quit [Read error: Connection reset by peer]
myrkraverk_ has joined #ocaml
germ_ has joined #ocaml
myrkraverk has quit [Ping timeout: 248 seconds]
Serpent7776 has joined #ocaml
myrkraverk has joined #ocaml
myrkraverk_ has quit [Ping timeout: 276 seconds]
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 276 seconds]
myrkraverk has joined #ocaml
bartholin has joined #ocaml
myrkraverk_ has quit [Ping timeout: 244 seconds]
toastal has joined #ocaml
Frostillicus has quit [Ping timeout: 245 seconds]
YuGiOhJCJ has joined #ocaml
Haudegen has joined #ocaml
toastal has left #ocaml [#ocaml]
toastal has joined #ocaml
Tuplanolla has joined #ocaml
Frostillicus has joined #ocaml
toastal has left #ocaml [#ocaml]
Frostillicus has quit [Ping timeout: 245 seconds]
toastal has joined #ocaml
olle has joined #ocaml
itszor has joined #ocaml
_jbrown_ has quit [Ping timeout: 245 seconds]
YuGiOhJCJ has quit [Quit: YuGiOhJCJ]
wbooze has quit [Ping timeout: 252 seconds]
<olle>
Could you program in 0xcaml now without using gc at all?
<olle>
In a memory safe-ish manner.
Frostillicus has joined #ocaml
inline has joined #ocaml
Frostillicus has quit [Quit: Frostillicus]
dhil has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
johnridesabike has joined #ocaml
agentcasey has joined #ocaml
<discocaml>
<sim642> I think this was asked recently in #oxcaml on Discord. My understanding is no(t yet)
<olle>
kk
Haudegen has joined #ocaml
szkl has joined #ocaml
cawfee has quit [Quit: WeeChat 4.6.3]
toastal has left #ocaml [#ocaml]
cawfee has joined #ocaml
toastal has joined #ocaml
toastal has left #ocaml [#ocaml]
Anarchos has joined #ocaml
toastal has joined #ocaml
Anarchos has quit [Ping timeout: 248 seconds]
Anarchos has joined #ocaml
agentcasey has quit [Ping timeout: 276 seconds]
Frostillicus has joined #ocaml
Anarchos has quit [Quit: Vision[]: i've been blurred!]
Anarchos has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
Frostillicus has quit [Read error: Connection reset by peer]