Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dune scripts #11519

Open
oberblastmeister opened this issue Mar 10, 2025 · 1 comment
Open

dune scripts #11519

oberblastmeister opened this issue Mar 10, 2025 · 1 comment
Labels

Comments

@oberblastmeister
Copy link

Haskell's cabal supports this

#!/usr/bin/env cabal
{- cabal:
build-depends: base ^>= 4.11
            , shelly ^>= 1.8.1
-}

main :: IO ()
main = do
    ...

The script can be made executable and running it will automatically download and build dependencies, compile the script, and then execute it. Subsequent runs where the file hasn't been changed will use the cached compilation. More information here https://cabal.readthedocs.io/en/stable/getting-started.html#running-a-single-file-haskell-script

With the advent of dune package management, we could do the same thing. For example:

#!/usr/bin/env dune
(* dune:
(depends
 base
 feather)
*)

open Feather

let () =
  process "ps" [] |. map_lines String.uppercase |. grep "BASH" |> run

This could make OCaml a nice replacement for shell scripts.

@nojb
Copy link
Collaborator

nojb commented Mar 10, 2025

@oberblastmeister Independently of any package management, this sounds like a nice feature for one-file projects!

Question: where does cabal store its build artifacts when running a one-file script in this way? Next to the script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants