is there any possibility to use haskell functions in unix shell scripts?
for instance:
#!/bin/bash
...
var1=value
...
# use haskell function with input from shell variable var1
# and store the result into another shell variable var2
var2=haskellFunction $var1
...
I want to use variables in shell scripts as arguments and results of haskell functions
Thanks in advance.
jimmy
Right now dynamic languages are popular in the scripting world, to the dismay of people who prefer statically typed languages for ease of maintenance. Fortunately, Haskell is an excellent candidate for statically typed scripting for a few reasons: Haskell has lightweight syntax and very little boilerplate.
A Unix shell is both a command interpreter and a programming language. As a command interpreter, the shell provides the user interface to the rich set of GNU utilities.
[ bsd3, library, program, system ] [ Propose Tags ] Provides a shell scripting environment for Haskell. It helps you use external binaries, and allows you to perform many shell-like functions, such as piping and redirection.
Use the -e
switch to ghc
, e.g.
var2=$(ghc -e "let f x = x*x + x/2 in f $var1")
For string processing, it is best to use Haskell's interact
in conjunction with bash's here strings:
var2=$(ghc -e 'interact reverse' <<<$var1)
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