4
简介:信息的类型的家庭情况
虽然检查出snoyman's "persistent"图书馆,我发现自己想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)
人们总是可以找实例源代码,但有时也可能是很难找到它,它可能隐藏在模板哈斯克尔生成的代码等
代码示例:
{-# 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
|]
这是怎么回事的上面的代码示例是Template-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的或任何其他工具?
@claus:10x。 ':浏览'很棒! '-ddump-splices'不显示TH生成的代码。也认为它显示比'pprint'好(''boo''vs'['b',\ n'o',\ n'o'\ n]'等),认为'runQ/pprint'不仅仅是倾销,我可以过滤它等等 – yairchu 2010-06-11 00:05:20