简体   繁体   English

Haskell中的正则表达式-了解多参数类型类签名

[英]Regex in Haskell - Understanding multi parameter typeclass signatures

I'm having hard time figuring out how to use Text.Regex package. 我很难弄清楚如何使用Text.Regex包。 What does signature below mean? 以下签名是什么意思?

class RegexOptions regex compOpt execOpt 
  | regex->compOpt execOpt, compOpt->regex execOpt, execOpt->regex compOpt

I understand that there are three type parameters to RegexOptions and that for each of them, the other two allow compiler to determine its type, but how? 我知道RegexOptions有三个类型参数,对于每个参数,另外两个允许编译器确定其类型,但是如何? What are types or constraints on regex compOpt and execOpt ? regex compOptexecOpt类型或约束是什么?

Side question. 附带问题。 What would be the type of this expression? 此表达式的类型是什么?

makeRegexOpts (defaultCompOpt { caseSensitive = False }) defaultExecOpt

and that for each of them, the other two allow compiler to determine its type 而对于每一个,其他两个允许编译器确定其类型

Not quite. 不完全的。 Each of them can be used to deduce the other two , that's what this fundep says. 他们每个人都可以用来推断其他两个人 ,这就是该基金的说法。

How this works? 如何运作? Well, magic ! 好吧, 魔术 No. The compiler will only allow you to declare one single instance with any particular type appearing at one of the arguments. 不会。编译器仅允许您声明一个单个实例,并且其中一个参数中出现任何特定类型。 Then, when it needs a RegexOptions instance and has already deduced any one of the type arguments, it can just look that instance up to obtain the other parameters. 然后,当它需要一个RegexOptions实例并且已经推导了任何一个类型参数时,它只需查找该实例即可获取其他参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM