Skip to content

dune scripts #11519

@oberblastmeister

Description

@oberblastmeister

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions