haskell和Unix shell脚本

jim*_*myt 9 unix shell scripting haskell interaction

是否有可能在unix shell脚本中使用haskell函数?

例如:

#!/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

...
Run Code Online (Sandbox Code Playgroud)

我想在shell脚本中使用变量作为haskell函数的参数和结果

提前致谢.

吉米

dav*_*420 10

使用-e开关ghc,如

var2=$(ghc -e "let f x = x*x + x/2 in f $var1")
Run Code Online (Sandbox Code Playgroud)

对于字符串处理,最好将Haskellinteract与bash的字符串结合使用:

var2=$(ghc -e 'interact reverse' <<<$var1)
Run Code Online (Sandbox Code Playgroud)