<强>说明:

虽然检查出 snoyman的“老大难” 图书馆,我发现自己想ghci中的(或其他工具)的援助搞清楚东西。

ghci中的:info似乎没有工作作为很好地与型家庭和数据家庭,因为它与“普通”类型的作用:

> :info Maybe
data Maybe a = Nothing | Just a     -- Defined in Data.Maybe
...
> :info Persist.Key Potato -- "Key Potato" defined in example below
data family Persist.Key val     -- Defined in Database.Persist
... (no info on the structure/identity of the actual instance)

人们总是可以寻找在源代码中的实例,但有时也可能是很难找到它,它可能被隐藏在模板的Haskell生成的代码等等。

代码示例:

{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeFamilies, QuasiQuotes #-}

import qualified Database.Persist as Persist
import Database.Persist.Sqlite as PSqlite

PSqlite.persistSqlite [$persist|
Potato
    name String
    isTasty Bool
    luckyNumber Int
    UniqueId name
|]

这是怎么回事在上面的代码示例是模板的Haskell是为我们生成代码在这里。因为所生成的代码使用它们的所有附加信息所不同的是QuasiQuotes是必需的。

我发现是做什么Persist.Key Potato

-- test.hs:
test = PSqlite.persistSqlite [$persist|
...
-- ghci:
> :l test.hs 
> import Language.Haskell.TH
> import Data.List
> runQ test >>= putStrLn . unlines . filter (isInfixOf "Key Potato") . lines . pprint
    where newtype Database.Persist.Key Potato = PotatoId Int64
type PotatoId = Database.Persist.Key Potato

<强>问题:

有没有更简单的方式来获得对类型家庭和数据家庭情况信息,使用ghci的或任何其他工具?

有帮助吗?

解决方案

-ddump-splices显示您的TH-生成的代码在这种情况下?

否则,:browse并为您提供有关数据的家庭情况信息,尽管不是类型系列。

您可能要提交 GHC票 - 在:browse输出看上去错位,和一个可能期望数据族实例中报告等类的实例,通过:info

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top