interface - 对象类型中的磅符号,在 F# 中
问题描述
我遇到过这个:
[<Interface>]
type ILogger =
abstract Debug: string -> unit
abstract Error: string -> unit
[<Interface>] type ILog = abstract Logger: ILogger
module Log =
let debug (env: #ILog) fmt = Printf.kprintf env.Logger.Debug fmt
let error (env: #ILog) fmt = Printf.kprintf env.Logger.Error fmt
从该页面:https ://bartoszsypytkowski.com/dealing-with-complex-dependency-injection-in-f/
我想知道类型前面的“#”符号在做什么:让调试(环境:#ILog)...
该页面的解释是这样的:
秘诀在于#ILog 签名,这意味着我们的环境可以是任何实现ILog 接口的泛型类型。
但我试图找到这方面的文档,但我的谷歌搜索没有成功。我在哪里可以阅读更多关于它的信息?
我的理解是,您可以传递实现特定接口的对象,使用 # 的函数将自动将该对象转换为接口并使用它。
但是,为什么他们在这里将其实现为 2 个接口而不是单个接口呢?
解决方案
推荐阅读
- list - 在 Dart 中获取从一个列表到另一个列表的累积总和/运行总计的更好方法
- excel - 文本导入 Excel
- r - 如何转换和计算数据?
- php - 获得最多 3 个变量的输出
- amazon-web-services - 将 ECS containerDefinition 命令移动到本地 - Terraform
- c - 错误:使用 makefile 在 C 中未定义对“proccess_External”的引用
- c++ - 我需要帮助修复试图在字符串中查找子字符串的代码
- javascript - 如果字符串等于多个字符串匹配
- python - Python dask groupby 不适用于“进程”调度程序
- r - R中的for循环读取数据