以 pointfree 风格书写 f x = g x x [英] Writing in pointfree style f x = g x x
问题描述
我正在学习 Haskell.很抱歉问了一个非常基本的问题,但我似乎找不到答案.我有一个由以下定义的函数 f:
I am learning Haskell. I'm sorry for asking a very basic question but I cant seem to find the answer. I have a function f defined by :
f x = g x x
其中 g 是一个已经定义的 2 个参数的函数.我如何编写这种 pointfree 风格?不使用 lambda 表达式.
where g is an already defined function of 2 arguments. How do I write this pointfree style? Edit : without using a lambda expression.
谢谢
推荐答案
f
可以用 Control.Monad.join
:
f = join g
函数 monad 上的
join
是构造无点表达式时使用的原语之一,因为它不能以无点样式本身定义(它的 SKI calculus 等效,.SII
— ap id id
in Haskell —不输入)
join
on the function monad is one of the primitives used when constructing point-free expressions, as it cannot be defined in a point-free style itself (its SKI calculus equivalent, .SII
— ap id id
in Haskell — doesn't type)
这篇关于以 pointfree 风格书写 f x = g x x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!