编程的本质 (6) 更多
-
第1页
阅读后记 之前看完本书对其与haskell typeclass类似的编程风格大为惊喜。今天才了解到,这个概念其实曾是一个c++0x正式的proposal( http://en.wikipedia.org/wiki/Concepts_ (C%2B%2B) ),看完这个proposal再看... (1回应) -
Chapter 3. Asso
这本书最有意思的地方倒不是这些算法的实现,而是作者认真地去确定算法的概念,接口,需要满足的数学属性,前置条件后置条件这些东西,并用c++伪代码表达出来,虽然不是非常严格。应该算是所谓的面向契约编程了。... (1回应) -
2.3. Collision.
首先用类型来表达书中的两个概念: type Transformation a = a -> a type Predicate a = a -> Bool 然后是实现: collision_point :: a -> Transformation a -> Predicate a -> Maybe a collision... (4回应) -
2.2 Orbits
使用上面介绍的 iterate 函数,这一节的 distance 函数也就一行代码的事,在叠加 f 函数的列表中查找 y 的存在: distance :: a -> a -> (a -> a) -> Maybe Int distance x y f = y `elemIndex` (ite... -
2.1 transform
power_unary 函数直接的翻译会是这样: power :: a -> Int -> (a -> a) -> a power x n f = loop n x where loop 0 x = x loop n x = loop (n-1) (f x) 而haskell标准库有更优雅的方案: iterate :: ... -
1.7 Concepts
template<typename Op> requires(BinaryOperation(Op)) Domain(Op) square(const Domain(Op)& x, Op op) { return op(x, x); } 用haskell翻译过来,信息量一个不少: square :: a -> (a -> a -&g...
>
➗的读书主页