我有这样的文件结构:
--- Database.hs ---
data Database = ...
...
--- User.hs ---
import Database
addUser :: Update Database ()
...
--- Post.hs
import Database
addPost :: Update Database ()
...
问题是,我需要在User.hs
和Post.hs
中调用makeAcidic ''Database [...]
,以使它们的函数酸性,但makeAcidic
同时为Database
生成IsAcidic
实例,因此GHC抱怨重复的实例声明。
好的,所以我想明白了。只需使用模板Haskell:分离定义即可
--- Database/Types.hs ---
data Database = ...
...
--- Database.hs ---
import Database.Types
import User
import Post
makeAcidic ''Database [addUser, addPost]
--- User.hs ---
import Database.Types
addUser :: Update Database ()
...
--- Post.hs ---
import Database.Types
addPost :: Update Database ()
...