Z template haskell docs on the VarI Info contructor:
A "wartość" zmienna (w przeciwieństwie do zmiennej typu, patrz TyVarI
). Pole Maybe Dec
zawiera Just
deklarację, która zdefiniowała zmienną - w tym RHS deklaracji - lub też Nothing
, w przypadku, gdy RHS jest niedostępna dla kompilatora. Obecnie ta wartość to zawszeNothing
: zwracanie RHS nie zostało jeszcze zaimplementowane z powodu braku zainteresowania.
Patrząc na ghc source mirror on github The string VarI
only appears twice, a zarówno w compiler/typecheck/TcSplice.lhs realizującego funkcję reifyThing
:
reifyThing :: TcTyThing -> TcM TH.Info
-- The only reason this is monadic is for error reporting,
-- which in turn is mainly for the case when TH can't express
-- some random GHC extension
reifyThing (AGlobal (AnId id))
= do { ty <- reifyType (idType id)
; fix <- reifyFixity (idName id)
; let v = reifyName id
; case idDetails id of
ClassOpId cls -> return (TH.ClassOpI v ty (reifyName cls) fix)
_ -> return (TH.VarI v ty Nothing fix)
}
reifyThing (AGlobal (ATyCon tc)) = reifyTyCon tc
reifyThing (AGlobal (ADataCon dc))
= do { let name = dataConName dc
; ty <- reifyType (idType (dataConWrapId dc))
; fix <- reifyFixity name
; return (TH.DataConI (reifyName name) ty
(reifyName (dataConOrigTyCon dc)) fix)
}
reifyThing (ATcId {tct_id = id})
= do { ty1 <- zonkTcType (idType id) -- Make use of all the info we have, even
-- though it may be incomplete
; ty2 <- reifyType ty1
; fix <- reifyFixity (idName id)
; return (TH.VarI (reifyName id) ty2 Nothing fix) }
reifyThing (ATyVar tv tv1)
= do { ty1 <- zonkTcTyVar tv1
; ty2 <- reifyType ty1
; return (TH.TyVarI (reifyName tv) ty2) }
reifyThing thing = pprPanic "reifyThing" (pprTcTyThingCategory thing)
Jak docs szablon Haskell powiedział, wartość używana dla tego pola jest zawsze Nothing
.
Pożeracz kopania, this code was added in 2003, w czymś, co wygląda jak przepisanie systemu reify. Wydaje się więc, że nie ma większego zainteresowania, aby to zadziałało, ponieważ od ponad 10 lat pole to zawsze miało wartość Nothing
. Zgaduję, że jeśli chcesz tę funkcję, musisz ją zaimplementować samodzielnie (lub zaproponuj dobry przypadek użycia na liście mailingowej ghc development, która zachęci kogoś do zrobienia tego).
To doskonałe pytanie. Próbowałem oznaczać definicję "INLINE" lub "INLINEABLE", i żadna nie robiła żadnej różnicy. Podejrzewam, że w ogóle nie jest to realizowane, ale nie wiem. – Carl
możliwy duplikat [Jak użyć szablonu Haskella do uzyskania treści funkcji?] (Http://stackoverflow.com/questions/13983391/how-to-use-template-haskell-to-get-thebody-of -funkcjonować) – jberryman