我想用C++调用haskell函数,并使用http://www.haskell.org/ghc/docs/7.0.2/html/users_guide/ffi-ghc.html上的教程.
所以我有一个haskell文件Foo.hs:
module Foo where
foreign export ccall foo :: Int -> IO Int
foo :: Int -> IO Int
foo n = return (length (f n))
f :: Int -> [Int]
f 0 = []
f n = n:(f (n-1))
Run Code Online (Sandbox Code Playgroud)
并呼吁
ghc Foo.hs
Run Code Online (Sandbox Code Playgroud)
它创建了一个Foo_stub.h:
#include "HsFFI.h"
#ifdef __cplusplus
extern "C" {
#endif
extern HsInt foo(HsInt a1);
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)
一个Foo_stub.c:
#define IN_STG_CODE 0
#include "Rts.h"
#include "Stg.h"
#ifdef __cplusplus
extern "C" {
#endif
extern StgClosure …Run Code Online (Sandbox Code Playgroud) 我创建了一个greasemonkey脚本,并希望在我的主页上提供"安装Greasemonkey"按钮.该按钮应该从重定向在addons.mozilla.org安装火狐插件Greasemonkey的备用和用户.在他们安装了greasemonkey后,我提供了一个"安装greasemonkey脚本"按钮,该按钮已经可以使用了.
是否可以直接在我的主页上添加"安装greasemonkey"按钮?理想情况下,将使用托管addons.mozilla.org上的插件,我不会在我自己的主机Greasemonkey的.
我正在编写一个 C++ 应用程序A,它在后台调用另一个应用程序B。一些命令行选项适用于应用程序A,但有些应转发给B。分隔应该使用双破折号--。
例如:
./my_executable_A -a --long_b some_file -- -c --long_d
Run Code Online (Sandbox Code Playgroud)
应该解析{"-a", "--long_b", "some_file"}在应用阿并转发{"-c", "--long_d"}到应用乙当它被称为甲。
我认为boost::program_options用于该任务可能有意义,但我没有找到此功能。这可能吗?
注意:用例是一个libfuse文件系统,其中一些选项将被转发到fuse_main()函数。
我有一个数据切片,想要为固定大小的子切片创建一个数组引用:
let slice: &[u8] = &[1, 2, 3, 4, 5];
let array_ref: &[u8; 2] = &slice[..2];
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用,因为&[..2]is的类型&[u8]而不是&[u8; 2]。
我知道<&[u8; 2]>::try_from(slice),但这会导致运行时检查,我更愿意使用不执行此运行时检查的 API,因为我知道在运行时满足了大小要求。
是否有任何 API 允许这样做?
假设有一个集合特征,其项目具有关联类型:
trait CollectionItem {
// ...
}
trait Collection {
type Item: CollectionItem;
fn get(&self, index: usize) -> Self::Item;
// ...
}
Run Code Online (Sandbox Code Playgroud)
Collection我可以以某种方式将其类型擦除为对和特征都使用动态调度的类型吗CollectionItem?即将其包装成如下所示:
struct DynCollection(Box<dyn Collection<Item=Box<dyn CollectionItem>>>);
impl DynCollection {
fn get(&self, index: usize) -> Box<dyn CollectionItem> {
// ... what to do here?
}
}
impl <C: Collection> From<C> for DynCollection {
fn from(c: C) -> Self {
// ... what to do here?
}
}
Run Code Online (Sandbox Code Playgroud)