我正在阅读/收听 Chris Taylor 关于代数数据类型的演示。
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
Given
Trio -> Bool should equal 8
为什么乘法是 8 而不是 6?
如果我理解正确的话,具体组合应该是
First -> True
First -> False
Second -> True
Second -> False
Third -> True
Third -> False
这不就是6个具体的实现吗Trio -> Bool
?
我缺少什么?
Those aren't full implementations. For the full implementations, it is like counting from 0 to 7 (which is a total of 8 = 23 numbers) in binary, with each line of each implementation representing one of the three bits. All the possibilities look like this (if we call our function 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)