Is it possible to write shell scripts in Haskell and if so, how do you do it? Just changing the interpreter like so?
#!/bin/ghci
Fortunately, Haskell is an excellent candidate for statically typed scripting for a few reasons: Haskell has lightweight syntax and very little boilerplate. Haskell has global type inference, so all type annotations are optional. You can type-check and interpret Haskell scripts very rapidly.
Shell scripts contain ASCII text and are written using a text editor, word processor or graphical user interface (GUI). The content of the script is a series of commands in a language that can be interpreted by the shell.
Tenex Shell This shell is recommended for programmers based on its C-like syntax, as those developers can use scripting features without any experience in sh or Bash.
Using ghci
will just load the module in GHCi. To run it as a script, use runhaskell
or runghc
:
#!/usr/bin/env runhaskell main = putStrLn "Hello World!"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With