Skip to content

Derive static versions of StandaloneDeriving instances with withStatic #16

@ABorgna

Description

@ABorgna

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions