[Solved]Are these statements of Haskell's `data` and `type` are right?

1.For data xxx,it will create a type named xxx with type constructor xxx,and create value constructor which can summon values related to type xxx if assign right expression to it (i.e. = cons | cons2)

2.For type XXX = XXXX,it will create a type named XXX which is equivalent with type XXXX.

Examples for above:

-- Could create a type named `Maybe a` with type constructor `Maybe a`
-- And to supply of it,use the value constructor `Just` or `Nothing`,which could be thought as values.
data Maybe a = Just a | Nothing

-- Also create a type named `MaybeOfInt` with its type constructor,which actually represent the type named `Maybe Int`.
type MaybeOfInt = Maybe Int

Are these statements of what I think of Haskell’s data and type true?:eyes:

And,welll,could I think Type is a special case of kind?

type just create an alias. Everywhere you wrote Maybe Int you can replace it with MaybeOfInt and vice versa. So if a function as a signature of f :: MaybeOfInt -> Int you can pass it a Maybe In.

2 Likes

This is wrong, it will not create a type named Xxx, it is just an alias for Xxxx, a convenience for the programmer.

Type is not a special case of Kind. A simple metaphor: as evey haskell expression has a type, every type has a kind.

λ> :type (Just 'c')
(Just 'c') :: Maybe Char
λ> :kind Maybe
Maybe :: * -> *
λ> :kind Maybe Char
Maybe Char :: *
2 Likes

Thanks for your reply!
Well,it seem that I’m not declaring clearly.The Type mentioned in my reply

is the Type annotation which I first met it in overview-of-type-in-type.And now I have found the answer after searching for the past hour.Though,thank you for you and the above guys’ correct!:smiling_face_with_three_hearts:

1 Like