S组合器在Haskell中 [英] S combinator in Haskell

查看:137
本文介绍了S组合器在Haskell中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

S 组合器的类比可以仅使用标准函数在Haskell中表达(没有通过等式来定义它)并且不使用lambda(匿名函数)?我期望它的类型是(a - > b - > c) - > (a - > b) - > a - >例如, K 组合器的类似物就是 const <

/ code>。



其实我试图表达函数 \ fx - > fxx 使用标准函数,但不能想到任何标准的非线性函数(这是一个函数多次使用它的参数)。

(( - >))解析方案

s =(*) r) Applicative 实例。


Can an analog of the S combinator be expressed in Haskell using only standard functions (without defining it by equation) and without using lambda (anonymous function)? I expect it to by of type (a -> b -> c) -> (a -> b) -> a -> c.

For example, an analog of the K combinator is just const.

In fact i am trying to express the function \f x -> f x x using standard functions, but cannot think of any standard non-linear function to start with (that is a function that uses its argument more than once).

解决方案

s = (<*>) for the ((->) r) Applicative instance.

这篇关于S组合器在Haskell中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆