I mean, most errors are not avoidable at the API level: write errors, permission errors, full filesystem, etc etc etc, can and need to be managed via Result/IO err, as you already do.
Writing to a closed fd feels like one of those problems that are be fixable with a Strict Enough API but:
not sure it actually exists in the Elm typesystem
not sure, if it exists, if it is nice enough to be worth using over a trivial withFile : (FD -> IO e a) -> IO e a
not sure, if it exists, if it’s flexible enough for all usecases
Something something records keeping tracks of open files via type level shenanigans, elm-css-ish style.
I think allowing either a value or a Promise should be flexible enough yet clean and avoid the issue.