this page上的示例3:
// comp :: (b -> c) -> (a -> b) -> (a -> c)
const comp = f=> g=> x=> f (g (x))
// comp2 :: (c -> d) -> (a -> b -> c) -> (a -> b -> d)
const comp2 = comp (comp) (comp)
// sub :: Number -> Number -> Number
const sub = x=> y=> y - x
// abs :: Number -> Number
const abs = x=> Math.abs
// diff :: Number -> Number -> Number
const diff = comp2 (Math.abs) (sub)
// gt :: Number -> Number -> bool
const gt = x=> y=> y > x
// lt :: Number -> Number -> bool
const lt = x=> y=> y < x
// eq :: a -> a -> bool
const eq = x=> y=> y === x
// (Number -> bool) -> Number -> Number -> bool
const testDifference = f=> comp2 (f) (diff)
console.log('testDifference gt', testDifference (gt(10)) (1) (3))
console.log('testDifference lt', testDifference (lt(4)) (6) (5))
console.log('testDifference eq', testDifference (eq(1)) (6) (5))
// almostSame :: Number -> Number -> bool
let almostSame = testDifference (lt(0.01))
console.log('almostSame', almostSame (5.04) (5.06))
console.log('almostSame', almostSame (3.141) (3.14))
中的测试$ other 是什么,我得到了$ other是函数的参数,但为什么Test和space在它之前呢?在这个例子中调用私有方法有什么大不了的?
function baz(Test $other)
答案 0 :(得分:0)
Test
这是一个没有功能的最基本的例子,因此也不是最好的学习资源。