启用了mpsGeneric的Key的Eq实例看起来很奇怪

时间:2016-05-11 09:58:19

标签: haskell yesod persistent

git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'

在这个haskell程序中,我启用了mpsGeneric开关,该程序的结果是:

{-# 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)

如果禁用mpsGeneric,结果为:

True
True
False
False

看来,上面的Eq实例已被打破。 我用

测试程序
True
False
False
True

此"功能"当我运行以下代码时,我整整一个下午都要杀了我

persistent of version 2.2.4.1
persistent-template of version 2.1.6

1 个答案:

答案 0 :(得分:1)

这是一个错误。它现在在github上报告:https://github.com/yesodweb/persistent/issues/560