简体   繁体   English

为什么没有数据构造函数的类型有效?

[英]Why are types with no data constructors valid?

This seems to be legal: 这似乎是合法的:

data MagazineInfo = Int String
    deriving (Show)

I am not sure if there is a default data constructor, but the above code compiles. 我不确定是否有默认数据构造函数,但上面的代码编译。

Why is the above valid Haskell, since I did not explicitly specify a value constructor? 为什么上面有效的Haskell,因为我没有明确指定值构造函数?

You do have a data constructor there--it's Int . 你有一个数据构造函数 - 它是Int Type names live in a separate namespace from data constructors, which is why you don't get an error even though there happens to be a type also named Int . 类型名称存在于与数据构造函数不同的命名空间中,这就是为什么即使碰巧存在名为Int的类型也不会出现错误的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM