2016-07-26 51 views
3

我有一個文件的結構是這樣的:Haskell:多個文件的酸性狀態?

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

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

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

的問題是,我要叫兩個User.hsPost.hsmakeAcidic ''Database [...],使它們的功能的酸性,但makeAcidic在同一時間產生Database所以GHC IsAcidic實例抱怨重複的實例聲明。

回答

5

好的,我想清楚了。只需將模板的定義與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() 
...