假如有人问我订阅号中的战斗号,我一定不假思索地想到:
图灵访谈
我知道,
“图灵访谈”的粉丝们多是品味极高的洋气人儿。
所以紧接楼上中文版访谈,这里给出了英文版!
练好了中英双语,来图灵翻译图书吧~
访谈嘉宾:
Adit Bhargava,
软件工程师,兼具计算机科学和美术方面的教育背景,在
adit.io
撰写编程方面的博客。
因为爱好,Adit踏入了编程殿堂。
Visual Basic 6 for Dummies
教会了他很多基础知识,但始终对算法没搞明白。直到遇到一位优秀的算法教授后,他才认识到这些概念是多么地简单且优雅。
几年前,他开始在adit.io上撰写图解式博文,介绍函数式编程、Git、机器学习和并发。图解式写作风趣幽默、化繁为简、清晰明确,受到大量读者的喜爱。
访谈中,我们主要聊了些:
-
为什么要写这样一本萌萌的算法入门书
-
封面插画背后的故事
-
Adit神秘的算法导师
-
Adit最喜欢的算法
-
评判算法的重要指标
-
编程学习低龄化
Why would you like to write such an introductory book, which is full of fascinating scenarios and cute illustrations drawn by hand?
I usually take notes for myself when I learn something, because it helps me learn. For example here are the notes I'm taking as I read "A Book Of Abstract Algebra" (attached). So this was a technique I had used in the past, and I thought others might find it useful also. So I wrote this
blog post
. People liked it and it made me think that a book with the same style would probably do pretty well too.
Let's enjoy Adit's explanation of Monad in pictures!
学习 Monad的渠道:
-
取得计算机科学专业的博士学位。
-
压根儿不学。这里根本用不到那些条条框框!
Functor 将一个普通函数应用到被封装的值上:
Applicative 将一个封装的函数应用到封装的值上:
Monad 将一个 “接受普通值并回传一个被封装值” 的函数应用到一个被封装的值上,这一任务由函数
>>=
(读作 bind)完成。听起来似乎很拗口,让我们来看个例子吧,还是熟悉的
Maybe
:
假设
half
是只对偶数感兴趣的函数:
half x = if even x
then Just (x `div` 2)
else Nothing
如果扔给
half
一个封装的值会怎样?
这时,我们需要用
>>=
把被封装的值挤到
half
中。猜猜
>>=
的照片:
再看看它的效果:
> Just 3 >>= half
Nothing
> Just 4 >>= half
Just 2
> Nothing >>= half
Nothing
这其中究竟发生了什么?Monad 是另一种类型类,这是它定义的一部分:
class Monad m where
(>>=) :: m a -> (a -> m b) -> m b
下图展示了
>>=
各个参数的意义:
下面的定义让
Maybe
成了 Monad:
instance Monad Maybe where
Nothing >>= func = Nothing
Just val >>= func = func val
来看看执行
Just 3
时发生了什么:
如果传入
Nothing
就更容易了:
你还可以把这些调用过程连起来,比如执行
Just 20 >>= half >>= half >>= half
会得到
Nothing
:
太棒啦!
(Taken from Adit's article
Functors, Applicatives, And Monads In Pictures
)
From the book cover, I thought it might be full of hand-drawn illustrations about mice. It seems not, for there’re other images like sheep, birds, rabbits, diagrams. Why would you put that picture in front of the book?
I wish I had a good answer for you! The people at Manning chose the picture on the cover. Manning was generally good about giving me a lot of control over the book, but for the cover, they really fell in love with this image and chose to use it.