代数数据类型的计数

8
我正在阅读/聆听克里斯·泰勒有关代数数据类型的演示。
链接:http://chris-taylor.github.io/blog/2013/02/10/the-algebra-of-algebraic-data-types/ 其中有一节是关于函数类型的,特别是这个例子。
data Bool = True | False
data Trio = First | Second | Third

鉴于法律

a -> b == B^A

鉴于

Trio -> Bool     should equal     8

为什么使用乘法时是8而不是6?

如果我理解正确,具体的组合应该是:

First  -> True
First  -> False
Second -> True
Second -> False
Third  -> True
Third  -> False

这难道不只是 Trio -> Bool 的六种具体实现吗?我是否遗漏了什么?
1个回答

19
那些不是完整的实现。对于完整的实现来说,就像在二进制中从0到7(总共8个= 23个数字)进行计数,每个实现的每行表示其中的一个三个位之一。所有可能性看起来像这样(如果我们将函数称为f):

1)

f First  = False
f Second = False
f Third  = False

2)

f First  = True
f Second = False
f Third  = False

3)

f First  = False
f Second = True
f Third  = False

4)

f First  = True
f Second = True
f Third  = False

5)

f First  = False
f Second = False
f Third  = True

6)

f First  = True
f Second = False
f Third  = True

7)

f First  = False
f Second = True
f Third  = True

8)

f First  = True
f Second = True
f Third  = True

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接