Learning Koka 2022-08-04
I'd mentioned yesterday that I want to think about more concrete problems before I mess with trying to do structured concurrency in Koka.
As to the specific thing I'm choosing, it's not a good fit, I don't think, but I'm interested in at least laying out why it's not. And what is it?
Okay, so, I never used CGI scripts directly. I used to see other people use them all over the place, but by the time I was working on web server stuff for work, I was doing things that used the WSGI. I don't know why, but I just decided, let's see how any of this actually worked.
So, I've got RFC 3875, and I'm looking over it and comparing what it wants to what's possible in Koka (assuming I don't write extensions).
Here's what I've concluded from what I've looked at so far:
- CGI deals with standard input, standard output, and environment variables. The environment variables are expected to have a bunch of structure that the script should interpret before it performs any other I/O.
- Koka should be entirely able to handle the standard output side of things. Writing CGI scripts in Koka would benefit from a library to generate HTML, and, I think, HTTP headers.
- Koka should be able to handle the environment variables. The main thing I would need, is to have a case insensitive comparison for traversing the association list. (Which I later realized, after mentioning the concept earlier, that Koka's standard library does expect and support.) And then a bunch of processing steps.
- I think the big stumbling block is the CONTENT_LENGTH variable. This is in octets, which is what you call bytes if you don't want to get well-actually-ed. The RFC states "the script MUST NOT attempt to read more than CONTENT_LENGTH bytes". Right now, Koka's facilities for reading from standard input are... limited. The standard library provides the readline() function, which reads from standard input, in UTF-8, either a line of text (discarding the newline), or 1023 code points, whichever is shorter; I'm not clear on what happens if it doesn't get an explicit end to the line within 1023 code points. In any case, the point is, CGI really wants the script to be working in bytes at the boundary, and I don't think Koka is up for that yet. I don't know if supporting this kind of thing is on the radar.
So, Koka, which is, keep in mind, experimental and under development, appears to not be ready for the entirety of a use case that it's not explicitly meant to support. I think that's fine for now, and I'd like to mess with the areas that it can support. If it works well, maybe I'll end up with a little static site generator. I don't see such a thing replacing Pelican for me, but it could be neat.
Anyway, I didn't exactly use my time super well today, so I'm not going to go much further for now. I'll try to break things down in a little more detail later.
Good night.