functional-programming - OCaml 编译错误:语法错误:需要模块路径
问题描述
由于谷歌上没有关于此的内容,因此我打开了此问题。
我正在尝试编译此代码:
module Random: Mirage_random.S = struct
include Mirage_random_stdlib
end
module Ipv4: Static_ipv4.Make(Random, Clock, Ethernet, Arp) = struct
include Static_ipv4
end
但我明白了:
root@66f08fd7c55b:/workspaces/ocaml_env/mirage-tcpip/examples/raw_ip_tcp_example# dune build raw_ip_tcp_example.exe
Entering directory '/workspaces/ocaml_env/mirage-tcpip'
File "examples/raw_ip_tcp_example/raw_ip_tcp_example.ml", line 44, characters 36-37:
44 | module Ipv4: Static_ipv4.Make(Random, Clock, Ethern
^
Error: Syntax error: module path expected.
您可以在此处查看 static_ipv4 文件https://github.com/mirage/mirage-tcpip/blob/master/src/ipv4/static_ipv4.mli#L17
我不知道为什么会发生此错误。我没有包括Clock
, Ethernet
,Arp
因为错误已经出现了Random
。您可以在此处查看随机签名:https ://github.com/mirage/mirage-random/blob/master/src/mirage_random.ml以及我在这里包含的实现https://github.com/mirage/mirage -随机标准库
解决方案
首先,你有一个语法错误,函子应用程序应该写成:
Static_ipv4.Make(Random)(Clock)(Ethernet)(Arp)
然后你有一个错误:Static_ipv4.Make(Random)(Clock)(Ethernet)(Arp)
是模块表达式,而不是模块类型。此外,尚不清楚您是否甚至需要签名约束。简单地写
module Ipv4 = struct
include Static_ipv4
let more = 0
end
如果您想制作Static_ipv4
模块的扩展版本,则可以使用。
但也许,您想在函子结果中添加一些函数?在这种情况下,您可以使用:
module Ipv4 = struct
include Static_ipv4.Make(Random)(Clock)(Ethernet)(Arp)
let an_new_and_shiny_function = ()
end
如果您真的想强制类型相同,则需要重用仿函数结果的签名:
module Ipv4: sig
include Mirage_protocols.IP with type ipaddr = Ipaddr.V4.t
val connect : ip:(Ipaddr.V4.Prefix.t * Ipaddr.V4.t) -> ?gateway:Ipaddr.V4.t ->
end
= struct
include Static_ipv4.Make(Random)(Clock)(Ethernet)(Arp)
let an_new_and_shiny_function.
end
推荐阅读
- sql - Oracle SQL Select:获取连接表的重复结果
- javascript - 在 typecipt 中为类创建动态方法
- python - Pygame:使用 blit 时图像未显示
- webassembly - 如何检测 WASM 部署到的设备?
- asp.net-core - 在 ASP.NET Core MVC 中客户端中止请求时出现未处理的 TaskCancelledException
- ios - 如何使用swift限制仅调用从AppStore安装的应用程序的api
- javascript - XMLHttpRequest 阻止我的曲线显示在脚本中
- javascript - 从使用 URL.createObjectURL 创建的 blob URL 中获取 Blob 对象
- ethereum - NFT:尝试运行 create_collectibles 脚本会引发执行恢复错误:这是来自 Patrick Collins Youtube 教程
- python - 仅在导入特定功能时出现循环导入错误