Live data from Hacker News

Zero-Cost POSIX Compliance: Encoding the Socket State Machine in Lean's Types

ngrislain.github.io

21–24 of 24 posts

Re: Zero-Cost POSIX Compliance: Encoding the Socket State Machine in Lean's Types

#21
post #6

This is cool stuff, but a nitpick: It’s not undefined behavior in the language sense in C to do socket ops on a bad file descriptor. It’s just an error from the kernel’s point of view, and the kernel will throw -errno at you.

Fair point! Updated. I’m definitely coming at this more from a Lean 4/formal methods perspective than a POSIX one.

Re: Zero-Cost POSIX Compliance: Encoding the Socket State Machine in Lean's Types

#22

Does this work in the face of state changing out from under the socket? I'm not super familiar with low level socket details but I'm thinking something like connect returning EINPROGRESS and you not knowing if the connection has completed. It may complete, it may fail, but during that time this state machine is invalid I think. It seems like strict logical programming like this gets much harder in the face of mutable…

You are right, what I wrote is more of a PoC. It's valid for blocking sockets on the happy path.

Re: Zero-Cost POSIX Compliance: Encoding the Socket State Machine in Lean's Types

#23
One thing I don’t understand is the table at the end. It says Rust requires 30 lines of code for a type state pattern, and I’m sure that Rust will be more verbose than Lean here, but wouldn’t all the typing shown in the article count as lines for Lean? I don’t see how it’s 0.

Re: Zero-Cost POSIX Compliance: Encoding the Socket State Machine in Lean's Types

#24
post #4

Lean doesn’t have any kind of substructural typing, does it? At a glance it looks like you need to manually (lexically) rebind the socket at each step in the operation, and there’s nothing stopping you from holding onto a socket in a now-invalid state and making mess of things, right? Also, boo AI slop. If you’re going to use AI to help write your technical blog posts please please please edit out all the “No X. No Y…

Yes the user has to be cooperative somehow. You could emulate linear/affine types like features with indexed monads though.
Post reply on HN