Instances declared with StandaloneDeriving are not recognized by withStatic, and they don't get their static version defined. The following program does not compile (missing instance for (Static (Show D))).
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StaticPointers #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# Language TemplateHaskell #-}
import Control.Distributed.Closure
import Control.Distributed.Closure.TH
import Data.Typeable
data D = D
deriving (Typeable)
withStatic [d|
deriving instance Show D
|]
showC :: forall a. (Typeable a, Static (Show a)) => Closure a -> String
showC a = unclosure $ static (\Dict -> show)
`cap` (closureDict :: Closure (Dict (Show a)))
`cap` a
main :: IO ()
main = do
putStrLn $ showC $ static D
Neither does withStatic work with derived instances
withStatic [d|
data D = D
deriving (Typeable, Show)
|]
-- Static (Show D) doesn't get defined
As a result, there is no way to auto-generate static versions of instances with default implementations.
Instances declared with
StandaloneDerivingare not recognized bywithStatic, and they don't get their static version defined. The following program does not compile (missing instance for (Static (Show D))).{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StaticPointers #-} {-# LANGUAGE StandaloneDeriving #-} {-# Language TemplateHaskell #-} import Control.Distributed.Closure import Control.Distributed.Closure.TH import Data.Typeable data D = D deriving (Typeable) withStatic [d| deriving instance Show D |] showC :: forall a. (Typeable a, Static (Show a)) => Closure a -> String showC a = unclosure $ static (\Dict -> show) `cap` (closureDict :: Closure (Dict (Show a))) `cap` a main :: IO () main = do putStrLn $ showC $ static DNeither does
withStaticwork with derived instancesAs a result, there is no way to auto-generate static versions of instances with default implementations.