Haskell:多个文件的酸状态?

时间:2016-07-26 02:03:23

标签: haskell acid-state

我有这样的文件结构:

--- Database.hs ---
data Database = ...
...

--- User.hs ---
import Database
addUser :: Update Database ()
...

--- Post.hs
import Database
addPost :: Update Database ()
...

问题是我需要在makeAcidic ''Database [...]User.hs中调用Post.hs以使其功能变为酸性,但makeAcidic同时生成IsAcidic Database的实例所以GHC抱怨重复的实例声明。

1 个答案:

答案 0 :(得分:5)

好的,我明白了。只需将定义与Template 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 ()
...