所以我使用文件,我需要知道文件X中最大的行.使用Unix awk会产生我正在寻找的Int.但是在Haskell中,我如何返回该值并将其保存到变量中?
我试着定义一些东西IO [Int] -> [Int]
maxline = do{system "awk ' { if ( length > x ) { x = length } }END{ print x }' filename";}
Run Code Online (Sandbox Code Playgroud)
不起作用原因:
Couldn't match expected type 'Int',against inferred type 'IO GHC.IO.Exception.ExitCode'
Run Code Online (Sandbox Code Playgroud) 我在Unix中的一个项目中创建了一些文件,它们很多,如果我想在另一个PC或文件夹中执行它,我需要将所有文件复制到那里.它们都是导入连接的.如何制作可执行的haskell程序?
我有例子:
main.hs - main where all the program executes; using,besides haskell, unix shell.
ex1.hs - basically types of data, some functions.
ex2.lhs - same as ex1.lhs but is literate with LaTeX
pic.jpg - picture to use on the pdflatex
package.sty - package needed to use some functions
Run Code Online (Sandbox Code Playgroud)
我如何进行并编译所有这些?我尝试使用ghc但总是出错:
>ghc -o MAIN main.hs ex1.hs ex2.lhs pic.jpg package.sty
Run Code Online (Sandbox Code Playgroud)
Failed to load interface for 'ex1.hs'
并且在导入ex1.hs的行中
好奇的是,如果我换进口ex1.hs到进口ex2.lhs线会给EX2错误
我正在使用FFmpeg开发一些Haskell项目.我需要从包含MP4文件的媒体文件夹批量创建并从所有这些文件创建屏幕截图.我得到了代码,并在Unix的终端上使用它.它可以工作,但是如何在一行中使它在Haskell中的系统"xxxx"中执行?
如果没有使用几个系统"xx"......
#/bin/sh
for i in $(ls *.mp4)
do
ffmpeg -i $i -vframes 7 -y -ss 10 -s 150x150 -an -sameq -f image2 -r 1/5 $i%1d.jpg
done
Run Code Online (Sandbox Code Playgroud)
我试过了:
import System.Cmd
function = do{system "#/bin/sh";
system "for i in $(ls *.mp4)";
system "do";
system "ffmpeg -i $i -vframes 7 -y -ss 10 -s 150x150 -an -sameq -f image2 -r 1/5 $i%1d.jpg";
system "done";}
Run Code Online (Sandbox Code Playgroud)
但它给出了一个错误:
-vframes: No such file or directory
/bin/sh: Syntax error: "done" unexpected
Run Code Online (Sandbox Code Playgroud) 我有这样的基本结构
typedef struct struck {
char* id;
char* mat;
int value;
char* place;
} *Truck;
Run Code Online (Sandbox Code Playgroud)
像这样的功能创建了该结构的新"实例":
Truck CTruck(char* id, char* mat, int value, char* place) {
Truck nT = (Truck) malloc(sizeof (Truck));
nT->value = value;
strcpy(nT->id, id);
strcpy(nT->mat, mat);
strcpy(nT->place, place);
return nT;
}
Run Code Online (Sandbox Code Playgroud)
我在第一次收到错误strcpy.它编译没有问题.