# Using \`ocaml\` and \`ocamlfind\` to run scripts without #-directives

**URL:** <https://discuss.ocaml.org/t/using-ocaml-and-ocamlfind-to-run-scripts-without-directives/16354>\
**Category:** Ecosystem\
**Tags:** ocamlfind, script, ocaml\
**Created:** [March 22, 2025, 8:18am UTC](https://discuss.ocaml.org/t/using-ocaml-and-ocamlfind-to-run-scripts-without-directives/16354 "2025-03-22T08:18:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [March 22, 2025, 9:59am UTC](https://discuss.ocaml.org/t/using-ocaml-and-ocamlfind-to-run-scripts-without-directives/16354/2 "2025-03-22T09:59:38Z")

</div>

> [@arvidj](#):
>
> but it does feel unsatisfactory.

Indeed. But I think you have pretty much exhausted the possibilities here. I always feel that `ocaml` is missing a great opportunity not to be more friendly to writing scripts. But doing so would require quite a bit of good and well coordinated design, not something the eco-system is known for (and backward compatibility problems quickly quick in).

Problems abound,[type checkability](https://discuss.ocaml.org/t/type-checking-ocaml-scripts/12474), [mess](https://github.com/dbuenzli/topkg/blob/5118b194ad08df97298b206648dd2f521b65d9e3/src/topkg_main.ml#L260-L266) and no proper strategy around exit codes, and of course the split you mention between compilable sources and non-compilable ones with directives.

Regarding the latter either the compiler could be changed to accept them (which has been suggested a couple of times, can’t find a reference right now) or it could be solved by defining [floating attributes](https://ocaml.org/manual/5.3/attributes.html#floating-attribute) for them which the `ocaml` interpreter would transform into equivalent `#require` directives (that would still leave the problem of the #! though). I think I initially had that design in `b0caml` but I eventually came back to [directives](https://erratique.ch/software/b0caml/doc/manual.html#semantics), not sure exactly why. But perhaps because I wanted to reuse as much as possible the existing directives and that at some point merlin [seemingly](https://github.com/ocaml/merlin/issues/1023) had no problem with them.

---

_[View the full topic](https://discuss.ocaml.org/t/using-ocaml-and-ocamlfind-to-run-scripts-without-directives/16354)._
