我有一个文件context.ml,其中定义了一个地图
module CtxMap = Map.make(struct type t = int let compare = compare end)
Run Code Online (Sandbox Code Playgroud)
和一个map_get类型的函数CtxMap.key -> 'a CtxMap.t -> 'a
如何将CtxMap声明添加到context.mli文件中?我无法找到办法,因为mli文件不能包含代码.
出于调试目的,我想在OCaml中有一个函数转换为字符串任意类型,调试器目前有一个,但是有一个很酷.
sexplib库是完美的,但事实是我不能修改我需要添加的所有类型with sexp,我也不能使用camlp4.
有这样的功能吗?(它不会出现在生产代码上,所以我接受了肮脏的解决方案)
像Haskell的Show类型类似的东西正是我的意思.
谢谢你的时间
我想要一个包含特征的元素的向量Eq,我需要异构向量.例如:
let mut x: Vec<Eq> = Vec::new();
x.push(1);
x.push("hello")
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息,指出Eq无法将其转换为对象:
error[E0038]: the trait `std::cmp::Eq` cannot be made into an object
--> src/main.rs:2:20
|
2 | let mut x: Vec<Eq> = Vec::new();
| ^^ the trait `std::cmp::Eq` cannot be made into an object
|
= note: the trait cannot use `Self` as a type parameter in the supertrait listing
Run Code Online (Sandbox Code Playgroud)
是否可以有一个指向我可以比较的东西的指针列表,无论它们的类型如何?