当纯脚本类型签名的一部分时,竖线字符 (|) 是什么意思?

What does the pipe character (|) mean when part of a purescript type signature?

我无法通过阅读可用的 docs 来准确理解这一点。

在Type docs的记录部分,它似乎与Row Polymorphism有关,但我不明白它的一般用法。带有 | 符号的类型签名是什么意思?

例如:

class Monad m <= MonadTell w m | m -> w where
  tell :: w -> m Unit

未使用 PureScript 中的管道 "generally"。根据上下文,它有多种用途。正如您所提到的,其中之一是用于类型行组合。另一个是函数守卫。

您引用的特定语法称为 "functional dependency"。它是 multi-parameter 类型 class 的 属性,它指定某些变量必须由其他变量明确确定。

在这种特殊情况下,语法意味着“for every m there can only one w”。 或者,用更通俗的语言来说,对于多个不同的 w,给定的 m 不能是 MonadTell

功能依赖性出现在许多其他地方。例如:

-- For every type `a` there is only one generic representation `rep`
class Generic a rep | a -> rep where

-- Every newtype `t` wraps only one unique inner type `a`
class Newtype t a | t -> a where