gpt4 book ai didi

haskell - 独特数据构造函数命名的惯用方式

转载 作者:行者123 更新时间:2023-12-05 03:19:04 26 4
gpt4 key购买 nike

<分区>

我可以在不同数据类型中使用相同名称(此处为名称)吗?

data Person
= Person
{
name :: String,
salary :: Int
}
deriving( Show )

data University
= University
{
-- nameu :: String, <--- this works fine
name :: String,
students :: [ Person ]
}
deriving( Show )

main = putStrLn $ show $ University {
name = "TAU",
students = [
Person { name = "Oren", salary = 740 },
Person { name = "Moish", salary = 920 },
Person { name = "Axel", salary = 612 }
]
}

当我尝试这样做时,出现了这个错误:

[1 of 1] Compiling Main             ( Main.hs, Main.o )

Main.hs:13:8: error:
Multiple declarations of ‘name’
Declared at: Main.hs:4:8
Main.hs:13:8
|
13 | name :: String,
| ^^^^

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com