简体   繁体   English

Haskell / Frege <= <和= <<关联性

[英]Haskell/Frege <=< and =<< associativity

According to Hoogle, the fixity of <=< (Kleisli monad composition, or "left fish") and =<< (reverse monad bind) is infixr 1 . 根据Hoogle的说法, <=< (Kleisli monad组成,或“左鱼”)和=<< (反向monad bind)的infixr 1infixr 1 If I'm looking at them correctly, an expression like, say 如果我正确地看着它们,就像说的那样

print <=< return =<< return "foo"

should be invalid, since it would've been equivalent to the equally invalid 应该是无效的,因为它等同于同样无效的

print <=< (return =<< return "foo")

But for some reason, though the first expression seems to be invalid in Haskell, as expected, Frege seems to have no complaints, and evaluates <=< before the =<< . 但由于某种原因,尽管第一个表达似乎在Haskell中无效,正如预期的那样,Frege似乎没有抱怨,并且在=<<之前评估<=<

I discovered this when I was messing around on pointfree.io to figure out how to make something like 当我在pointfree.io上弄乱如何弄清楚如何制作类似的东西时,我发现了这一点

foo >>= (bar <=< baz)

point-free, and it gave me 没有点,它给了我

bar <=< baz =<< foo

which doesn't look quite right, considering the fixities. 考虑到固定性,这看起来不太正确。

Frege is like Haskell, but Frege is not Haskell. Frege 就像 Haskell,但Frege 不是 Haskell。 And in Frege, the fixities of those operators are different: =<< is infixr 2 and <=< is infixr 3 . 在弗雷格,这些算子的infixr 2是不同的: =<<infixr 2<=<infixr 3 So since <=< has lower precedence, bar <=< baz =<< foo is naturally parsed as (bar <=< baz) =<< foo . 因此,由于<=<具有较低的优先级, bar <=< baz =<< foo自然被解析为(bar <=< baz) =<< foo

(In fact, =<< and <=< have different types in Frege than they do in Haskell: instead of a Monad constraint, they have a Bind constraint, where Bind is like Monad without pure / return .) (事实上​​, =<<<=<在弗雷格有不同的类型 ,而不是在Haskell中:不是Monad约束,它们有一个Bind约束,其中Bind就像没有pure / return Monad 。)


Yes, Frege describes itself as "a Haskell for the JVM", but they mean " a Haskell" in the sense that Common Lisp is a Lisp, and Scheme is a Lisp, and Clojure is a Lisp. 是的, 弗雷格将自己描述为“一个Haskell的JVM”,但他们的意思是“ 一个 Haskell”在某种意义上说,Common Lisp是一个Lisp和计划是一个Lisp和Clojure是一个Lisp。 It's odd to see "Haskell" used in that way; 看到“Haskell”以这种方式使用是很奇怪的; it would be more normal to see "a Haskell-like language for the JVM", or something stronger. 看到“JVM的类似Haskell的语言”或更强大的东西更为正常。 But Frege is so similar that I can see why. 但弗雷格非常相似,我可以理解为什么。


Also, you're right: that does appear to be a bug in pointfree (the program that backs pointfree.io )! 另外,你说对了: 确实出现了一个错误pointfree (即备份程序pointfree.io )! pointfree is supposed to generate Haskell code, not Frege, so the fact that that transformation is invalid means it's doing the wrong thing. pointfree应该生成Haskell代码,而不是Frege,因此转换无效的事实意味着它做错了。

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

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