mirror of
https://github.com/tweag/distributed-closure.git
synced 2024-11-22 03:06:47 +03:00
Allow instance Typeable in withStatic blocks
`Typeable` instances are not user defined. But the user nevertheless sometimes needs static evidence of typeability. The solution is to allow users to write ```haskell withStatic [d| instance Typeable T |] ``` for any datatype `T`. `withStatic` will generate static evidence, but won't pass through the instance declaration itself, since it is illegal.
This commit is contained in:
parent
793ee0627d
commit
6059d410c4
@ -82,7 +82,7 @@ double = (*2)
|
||||
newtype SerializableInt = SI Int deriving (Generic, Typeable)
|
||||
withStatic [d|
|
||||
instance Binary SerializableInt
|
||||
instance Serializable SerializableInt
|
||||
instance Typeable SerializableInt
|
||||
|]
|
||||
|
||||
-- | Demonstration of client server interactions.
|
||||
|
@ -92,7 +92,9 @@ mangleName name@(TH.Name occ fl) = case fl of
|
||||
-- @
|
||||
--
|
||||
-- You will probably want to enable @FlexibleContexts@ and @ScopedTypeVariables@
|
||||
-- in modules that use 'withStatic'.
|
||||
-- in modules that use 'withStatic'. 'withStatic' can also handle non-user
|
||||
-- generated instances like 'Typeable' instances: just write @instance Typeable
|
||||
-- T@.
|
||||
withStatic :: TH.DecsQ -> TH.DecsQ
|
||||
withStatic = (>>= go)
|
||||
where
|
||||
@ -140,5 +142,9 @@ withStatic = (>>= go)
|
||||
let staticins = TH.InstanceD staticcxt statichd methods
|
||||
#endif
|
||||
decls' <- go decls
|
||||
return (ins : sigf : declf : staticins : decls')
|
||||
case hd of
|
||||
TH.AppT (TH.ConT nm) _ | nm == ''Typeable ->
|
||||
return (sigf : declf : staticins : decls')
|
||||
_ ->
|
||||
return (ins : sigf : declf : staticins : decls')
|
||||
go (decl:decls) = (decl:) <$> go decls
|
||||
|
Loading…
Reference in New Issue
Block a user