简体   繁体   English

数据类型声明中的多个声明错误

[英]Multiple declaration error in data type declaration

I'm currently building aa Twitter CLI client in Haskell, and I have a data type that represents a DM and one that represents a tweet. 我目前正在Haskell中构建一个Twitter CLI客户端,我有一个代表DM的数据类型和一个代表推文的数据类型。 However, I get a multiple declaration error because I have to use the same name for both: 但是,我收到多个声明错误,因为我必须使用相同的名称:

data Users =  Users { screen_name :: String } deriving(Show, Generic)


data Tweet = Tweet { text :: !Text,
                     retweeted :: Bool,
                     user :: Users
                   } deriving (Show, Generic)

data DM = DM { text :: !Text,
               sender_screen_name :: String
             } deriving (Show, Generic)

Does someone know a solution for this particular problem? 有人知道这个特定问题的解决方案吗?

As defined here , the named members are just functions that are used to call the values in your data structure. 作为定义在这里 ,已命名的成员只是被用来调用数据结构中的值的功能。

So, if you really want to use them, you can do so by using the language extension. 因此,如果您真的想要使用它们,可以使用语言扩展来实现。 You can do that by declaring this in your file: 你可以通过在你的文件中声明这个来做到这一点:

{-# LANGUAGE DuplicateRecordFields #-}

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

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