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?
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.
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!