7
votes

I'm reading/listening to Chris Taylor's presentation on algebraic data types.

http://chris-taylor.github.io/blog/2013/02/10/the-algebra-of-algebraic-data-types/

And there's a section on function types. Specifically the example

data Bool = True | False
data Trio = First | Second | Third

Given the law

a -> b == B^A

Given

Trio -> Bool     should equal     8

Why 8 and not 6 via multiplication?

If I'm understanding this correctly, the concrete combinations should be

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

Isn't that just 6 concrete implementations of Trio -> Bool?

What am I missing?

1

1 Answers

18
votes

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