3 ms·
Extract expression looks amazing. These days I write a lot of ocaml. I used to write a bit of Common Lisp though I don’t write much of that nowadays. The thin
by dan-robertson 7y ago
Extract expression looks amazing.
These days I write a lot of ocaml. I used to write a bit of Common Lisp though I don’t write much of that nowadays.
The thing I miss most when writing ocaml is paredit, a mode for emacs to edit sexps keeping them balanced. There is a more generic mode, smartparens, which can be used in other modes but it doesn’t work super well for ocaml: it can’t automatically add the required delimiters (though it isn’t clear that would always be wanted) and it struggles with multi-char delimiters, eg:
(* comments *)
[| arrays |]
{| unescaped strings |}
{foo| harder unescaped strings |foo}
And because the structure of ocaml involved other delimiters that smartparens can’t cope with, you miss out on a lot of structure editing.
But that said, maybe it is hard to edit structure that is less plain to see. Swapping two lines like this:
let foo = x y in
let bar = a b in
...
Seems like a natural operation but the same thing in lisp is quite an unnatural operation (the indentation style of ocaml hides that the second let is really nestled inside the first). Incidentally paredit has an operation to do this but it’s pretty confusing (something like, take the sexps backwards from the point to the start of the smallest list strictly containing the point and swap them with the sexps going backwards from (excluding) the smallest list strictly containing the point to the start of the smallest list strictly containing the smallest list strictly containing the point.
Another ocaml operation would be merging/splitting lets into a let ... and. But this would be even more unnatural in the equivalent lisp structure (perhaps one reason is that parallel lets are idiomatic in lisp but sequential lets are idiomatic in ocaml so it isn’t really a common operation to do in lisp).
There are a few structure editing features that sort of work in the normal ocaml modes of Tuareg with merlin. One is a “select more” operation which understands the syntax a bit. Another is a forward/backward defun operation which works a lot of the time and can be useful. Merlin also offers the ability to expand patterns based on the type they are matching (eg to expand _ into (_,_,_) or to the names of the record fields). There is also a “construct” operation which I’ve not really been able to figure out (I usually just abuse the destruct operation somehow) and some kind of type hole syntax (like this: (??)) which only merlin understands and which really confuses the compiler proper.
I’m pretty excited to try out this structure editing improvement, or indeed any structure editing or type-directed editing features.
- j88439h84 7y ago> The thing I miss most when writing ocaml is paredit Have you tried smartparens? https://smartparens.readthedocs.io/ https://smartparens.readthedocs.io/
- dan-robertson 7y agoI describe it in and after the paragraph you took that quotation from.
- j88439h84 7y agoOops
- gopiandcode 7y agoAs it happens, my main inspiration for writing this plugin was primarily due to the extensive support Emacs provides for performing structural edits in lisp. After having experienced the ease and speed at which you can naturally transform lisp programs by using the expression-level movement and editing commands, it was rather annoying to find myself frequently relying on character level movements to account for small issues with tuareg/merlin's movement commands. Also, after actually setting this whole thing up, I now believe ocaml has the potential to provide an even better editing experience than lisp if structural editing is properly implemented, as the comparative lack of delimiters means that ocaml is quite quick to type in (and structural support should mean that this doesn't come at the cost of movement speed). Hopefully I've got the ball rolling with regards to structural editing of ocaml code, and I'm eager to see how this area progresses.