启用了 mpsGeneric 的 Key 的 Eq 实例看起来很奇怪
The Eq instance of a Key with mpsGeneric enabled seems strange
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
module Main
where
import Database.Persist.Sql
import Database.Persist.TH
share
[mkPersist
sqlSettings
{ mpsGeneric = True
, mpsPrefixFields = False
, mpsEntityJSON = Just EntityJSON
{ entityToJSON = 'keyValueEntityToJSON
, entityFromJSON = 'keyValueEntityFromJSON
}
, mpsGenerateLenses = False
}
, mkMigrate "abc"]
[persistLowerCase|
Test
a String
|]
main :: IO ()
main = do
print $ (toSqlKey 1 :: TestId) /= (toSqlKey 1 :: TestId)
print $ (toSqlKey 1 :: TestId) == (toSqlKey 1 :: TestId)
print $ (toSqlKey 1 :: TestId) /= (toSqlKey 2 :: TestId)
print $ (toSqlKey 1 :: TestId) == (toSqlKey 2 :: TestId)
在这个haskell程序中,我启用了mpsGeneric开关,这个程序的结果是:
True
True
False
False
如果禁用mpsGeneric,结果是:
True
False
False
True
看来,上面那个Eq实例坏了。
我用
测试程序
persistent of version 2.2.4.1
persistent-template of version 2.1.6
这个 "feature" 让我整个下午都死了 ,当我 运行 以下代码时:
filter (/= someKey) [key1, key2, key3]
这是一个错误。现在 github 报道:https://github.com/yesodweb/persistent/issues/560
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
module Main
where
import Database.Persist.Sql
import Database.Persist.TH
share
[mkPersist
sqlSettings
{ mpsGeneric = True
, mpsPrefixFields = False
, mpsEntityJSON = Just EntityJSON
{ entityToJSON = 'keyValueEntityToJSON
, entityFromJSON = 'keyValueEntityFromJSON
}
, mpsGenerateLenses = False
}
, mkMigrate "abc"]
[persistLowerCase|
Test
a String
|]
main :: IO ()
main = do
print $ (toSqlKey 1 :: TestId) /= (toSqlKey 1 :: TestId)
print $ (toSqlKey 1 :: TestId) == (toSqlKey 1 :: TestId)
print $ (toSqlKey 1 :: TestId) /= (toSqlKey 2 :: TestId)
print $ (toSqlKey 1 :: TestId) == (toSqlKey 2 :: TestId)
在这个haskell程序中,我启用了mpsGeneric开关,这个程序的结果是:
True
True
False
False
如果禁用mpsGeneric,结果是:
True
False
False
True
看来,上面那个Eq实例坏了。 我用
测试程序persistent of version 2.2.4.1
persistent-template of version 2.1.6
这个 "feature" 让我整个下午都死了 ,当我 运行 以下代码时:
filter (/= someKey) [key1, key2, key3]
这是一个错误。现在 github 报道:https://github.com/yesodweb/persistent/issues/560