# Write CLI scripts in Elm (IO Monad)

**URL:** <https://discourse.elm-lang.org/t/write-cli-scripts-in-elm-io-monad/7543>\
**Category:** Request Feedback\
**Created:** [July 13, 2021, 2:45pm UTC](https://discourse.elm-lang.org/t/write-cli-scripts-in-elm-io-monad/7543 "2021-07-13T14:45:28Z")\
**Posts on this page:** 1\
**Showing post:** 33

<div class="post-metadata">

**Author:** ![miniBill](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/minibill/32/800_2.png) [@miniBill](https://discourse.elm-lang.org/u/miniBill)\
**Post date:** [July 22, 2021, 6:24pm UTC](https://discourse.elm-lang.org/t/write-cli-scripts-in-elm-io-monad/7543/33 "2021-07-22T18:24:55Z")

</div>

# Files API

> [@albertdahlin](#):
>
> - 90% of the use cases for this package would be satisfied with just reading / writing whole files at once.

Yupp

> [@albertdahlin](#):
>
> - Writing to closed file descriptors are just one of all the problems you can have and need to watch out for. I am afraid that solving this without something like linear types would make API feel very complex. But of course I am open to suggestions and I will try to think in the lines the ideas you are describing.

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:

1. not sure it actually exists in the Elm typesystem
2. 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`
3. 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._

> [@albertdahlin](#):
>
> # Call JS
> 
> I had that in the beginning but then I wanted to do async stuff, like
> 
> ```auto
> sleep: function(delay) {
> setTimeout(this.send, delay);
> }
> 
> ```
> 
> so I went with the more flexible approach of using callbacks. My thinking was that increased flexibility outweighs the increased risk. I’m open to other opinions or suggestions here though, maybe it is better to revert to returning values.  
> Is it maybe a better idea to have the functions return either a value or a `Promise` to allow both styles?

I think allowing either a value or a `Promise` should be flexible enough yet clean and avoid the issue.

---

_[View the full topic](https://discourse.elm-lang.org/t/write-cli-scripts-in-elm-io-monad/7543)._
