该类型有多少个不同的值?

Log*_*gik 0 haskell types

我有一个给定的类型

type Foo = Either (Bool, ()) (Maybe Ordering)
Run Code Online (Sandbox Code Playgroud)

我知道该类型Bool有两个不同的值:TrueFalse

假设,以下类型是否正确:

type Foo = Either (Bool, ()) (Maybe Ordering)
Run Code Online (Sandbox Code Playgroud)

2+2+1+2+3 = 10考虑到其他类型的构建方式,具有不同的值:

data Either a b = Left a | Right b
data Maybe a = Just a | Nothing
data Ordering = EQ | LT | GT
Run Code Online (Sandbox Code Playgroud)

Wil*_*ess 6

你有什么:

        type Foo = Either (Bool, ()) (Maybe Ordering)
Run Code Online (Sandbox Code Playgroud)

Either 携带一种类型的值,或另一种类型的值:

data Either a b = Left a | Right b
    |Either a b|  =  |a| + |b|

        |Foo| = |(Bool, ())| + |Maybe Ordering|
Run Code Online (Sandbox Code Playgroud)

(,)携带两个值,每个值都有对应的类型,因此对于每个特定a类型的值,都有特定类型值的|b|选择b

data (,) a b = (a , b)
    |(a,b)| = |a| * |b|

        |Foo| = |Bool| * |()| + |Maybe Ordering|
Run Code Online (Sandbox Code Playgroud)

Bool就像Either () ()

data Bool = False | True
    |Bool|  =  1  +  1 

        |Foo| = (1 + 1) * |()| + |Maybe Ordering|
Run Code Online (Sandbox Code Playgroud)

()只有一个值,()

data () = ()
    |()| = 1

        |Foo| = (1 + 1) * 1  +  |Maybe Ordering|
Run Code Online (Sandbox Code Playgroud)

Maybe a就像Either () a

data Maybe a = Nothing | Just a
    |Maybe a|   =   1  +  |a|

        |Foo| = (1 + 1) * 1  +  (1 + |Ordering|)
Run Code Online (Sandbox Code Playgroud)

Ordering就像Either () (Either () ())

data Ordering = EQ | LT | GT
    |Ordering| = 1 +  1 +  1

        |Foo| = (1 + 1) * 1  +  (1 + (1 + 1 + 1))
Run Code Online (Sandbox Code Playgroud)

你做数学。:)