Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive static versions of StandaloneDeriving instances with withStatic #16

Open
ABorgna opened this issue Apr 17, 2018 · 0 comments
Open

Comments

@ABorgna
Copy link

ABorgna commented Apr 17, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants