我在ocaml项目工作中发现了一些我不太懂的东西.
假设我正在使用OCaml标准库的模块Array和List模块.它们都实现了功能length但具有不同的类型.在List模块中,这是它的类型:
length: a' list -> int
Run Code Online (Sandbox Code Playgroud)
在Array模块中,它具有以下类型:
length: a' array -> int
Run Code Online (Sandbox Code Playgroud)
但后来我希望你通过open关键字在我实现的同一个模块中使用这两个模块:
open List
open Array
Run Code Online (Sandbox Code Playgroud)
当我尝试length在列表上使用该函数时,我在编译期间遇到了类型错误.
由于OCaml是一种强大的静态类型语言,我想知道为什么编译器不知道我想要列表模块的长度函数,因为我声明我正在使用它们.
在我将新内容添加-Weverything到Clang后other warning flags,我开始收到所有NSAsserts的警告:
Varargs argument missing, but tolerated as an extension
Run Code Online (Sandbox Code Playgroud)
我该如何解决此问题,或者禁止此警告?
我试图实现用于反转每个像素的蓝色部分的算法BufferedImage使用BufferedImageOp类,如解释在这里.我的尝试导致了这种方法的创建:
private BufferedImage getInvertedVersion(BufferedImage source) {
short[] invert = new short[256];
short[] straight = new short[256];
for (int i = 0; i < 256; i++) {
invert[i] = (short)(255 - i);
straight[i] = (short)i;
}
short[][] blueInvert = new short[][] { straight, straight, invert }; //Red stays the same, Green stays the same, Blue is inverted
BufferedImageOp blueInvertOp = new LookupOp(new ShortLookupTable(0, blueInvert), null);
//This produces error #1 when uncommented
/*blueInvertOp.filter(source, source);
return source;*/ …Run Code Online (Sandbox Code Playgroud) 在Qt,
QFileDialog *dlg = new QFileDialog();
QDir dir = dlg->getExistingDirectory(this, tr("Choose folder"), qgetenv("HOME"));
Run Code Online (Sandbox Code Playgroud)
打开文件夹选择对话框.选择文件夹后(按选择按钮),文件夹不会自动关闭.所以我尝试过:
if(dlg->close() == true) delete(dlg);
Run Code Online (Sandbox Code Playgroud)
当我调试dlg-> close()时返回true并且命中了删除代码(dlg).文件夹选择器对话框仍未关闭.
我正在使用Ubuntu 11.10 64位操作系统.使用存储库中的Qt库.
我的最终目的是显示文件夹选择器对话框,一旦选择了文件夹,对话框应该关闭.之后,处理应该继续.这该怎么做?
提前致谢.
我已经定义了两种记录类型如下:
(* in module A*)
type reg = {name: string; mutable value: Big_int.big_int}
type exp = Reg of reg | Other
Run Code Online (Sandbox Code Playgroud)
(* in module B*)
type abstr = Top | Bot | Elt of int
type register = {name: string; mutable value: abstr}
Run Code Online (Sandbox Code Playgroud)
在模块B中,我有一个列表,我称之为l,exp并且我正在进行模式匹配.所以我有这样的事情:
List.fold_left (fun l elt ->
let str =
match elt with
| A.Reg r -> r.name
| _ -> failwith "exception" in
l@[{name = str; value = Bot}]) [] l
Run Code Online (Sandbox Code Playgroud)
但是我得到以下错误:表达式具有类型A.reg但是期望类型为register …
编写一个Ocaml函数list_print : string list -> unit,从左到右打印列表中的所有字符串:
所以让我们说我有一个Ocaml函数list_print: string list -> unit可以打印从左到右的列表中的所有字符串.现在正确的解决方案是:
let list_print lst = List.fold_left (fun ( ) -> fun s -> print_string s) () lst;;
Run Code Online (Sandbox Code Playgroud)
但在编写我的解决方案时,我是这样编写的:
let list_print lst = List.fold_left (fun s -> print_string s) () lst;;
Run Code Online (Sandbox Code Playgroud)
但这给了我
错误:此表达式具有类型单位,但表达式需要类型为"a - > string"
为什么在乐趣之前我需要第一个参数fun() - >?我还是Ocaml的新手,所以这种类型的系统让我很困惑
我最近开始使用emacs编写我的程序代码.我想知道是否有一个"命令" 直接从行的开头到达第n个字符而不使用任何技巧(比如重复n次 C-f).我简要介绍了emacs手册但没有找到任何内容.