Comments (8)
Java实现Y组合子
import lombok.val;
import java.util.function.Function;
public class YCombinator {
public static <T, R> Function<T, R> of(Function<Function<T, R>, Function<T, R>> f) {
Function<Function, Function<T, R>> r = p -> {
@SuppressWarnings("unchecked")
val w = (Function<Function, Function<T, R>>) p;
return f.apply(param -> w.apply(w).apply(param));
};
return r.apply(r);
}
}
from blog.
Java实现Y组合子 简化版
import java.util.function.Function;
public class YCombinator {
public static <T, R> Function<T, R> of(Function<Function<T, R>, Function<T, R>> f) {
return n -> f.apply(of(f)).apply(n);
}
}
from blog.
Go实现Y组合子
type RecFunc func(n interface{}) interface{}
func YComb(f func(RecFunc) RecFunc) RecFunc {
var r = func(p interface{}) RecFunc {
var w = p.(func(v interface{}) RecFunc)
return f(func(param interface{}) interface{} {
return w(w)(param)
})
}
return r(r)
}
from blog.
Go实现Y组合子 简化版
type RecFunc func(interface{}) interface{}
func YComb(f func(RecFunc) RecFunc) RecFunc {
return func(n interface{}) interface{} {
return f(YComb(f))(n)
}
}
from blog.
Objective-C实现Y组合子
#define YCombinator(ARG_TYPE, RET_TYPE, REC_NAME, IMP_BLOCK) \
^RET_TYPE (^(RET_TYPE (^(^f)(RET_TYPE (^)(ARG_TYPE)))(ARG_TYPE)))(ARG_TYPE) { \
RET_TYPE (^(^r)(id))(ARG_TYPE) = ^(id p) { \
RET_TYPE (^(^w)(id))(ARG_TYPE) = p; \
return f(^RET_TYPE (ARG_TYPE param) { \
return w(w)(param); \
}); \
}; \
return r(r); \
}(^RET_TYPE (^(RET_TYPE (^REC_NAME)(ARG_TYPE)))(ARG_TYPE) { \
return IMP_BLOCK; \
})
from blog.
Objective-C实现Y组合子 简化版
#define YCombinator(NAME, ARG_TYPE, RET_TYPE) \
typedef RET_TYPE(^NAME##RecFunc)(ARG_TYPE); \
NAME##RecFunc NAME(NAME##RecFunc(^f)(NAME##RecFunc)) { \
return ^RET_TYPE(ARG_TYPE n) { \
return f(NAME(f))(n); \
}; \
}
from blog.
Kotlin实现Y组合子
object YCombinator {
fun <T, R> of(f: YFunction<YFunction<T, R>, YFunction<T, R>>): YFunction<T, R> {
return object : YFunction<T, R> {
override fun apply(t: T): R {
return f.apply(of(f)).apply(t)
}
}
}
interface YFunction<in T, out R> : Function<R> {
fun apply(t: T): R
}
}
from blog.
Kotlin实现Y组合子 高阶函数
object YCombinator {
fun <T, R> of(f: ((T) -> R) -> ((T) -> R)): (T) -> R {
return { t: T -> f(of(f))(t) }
}
}
from blog.
Related Issues (20)
- Maven的多继承 HOT 2
- 浅尝Java Instrumentation HOT 9
- 浅尝Java ClassLoader HOT 6
- SimpleDateFormat的隐藏技能
- 浅尝Cobra HOT 1
- 做一些摘抄 HOT 14
- 浅尝Kotlin HOT 3
- 领域实体类
- PECS - producer-extends, consumer-super HOT 5
- CircularFifoQueue vs EvictingQueue HOT 1
- 浅尝Hazelcast HOT 14
- 浅尝HyperLogLog HOT 6
- 信息熵 HOT 1
- Go 开发笔记 HOT 2
- 0x5f375a86
- 空方法编译报错?!
- Lombok it! HOT 4
- 注解到底是什么
- 缓存风险
- 日常学习笔记 2024
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.