Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Role of static should be nominal #12

Merged
merged 1 commit into from
Oct 4, 2016
Merged

Role of static should be nominal #12

merged 1 commit into from
Oct 4, 2016

Conversation

edsko
Copy link
Member

@edsko edsko commented Feb 1, 2016

To see why, consider

    ``` haskell
    {-# OPTIONS_GHC -Wall #-}
    module Main (main) where

    import Control.Distributed.Static
    import Data.Rank1Dynamic
    import Data.Rank1Typeable
    import GHC.Prim (coerce)
    import GHC.Types (Coercible)
    import Unsafe.Coerce (unsafeCoerce)

    newtype T = T Bool
      deriving (Show)

    remoteTable :: RemoteTable
    remoteTable = registerStatic "$true" (toDynamic True)
                . registerStatic "$unsafeCoerce" (toDynamic (unsafeCoerce :: ANY1 -> ANY2))
                $ initRemoteTable
    staticUnsafeCoerce :: Static (a -> b)
    staticUnsafeCoerce = staticLabel "$unsafeCoerce"

    staticTrue :: Static Bool
    staticTrue = staticLabel "$true"

    staticCoerce :: Coercible a b => Static a -> Static b
    staticCoerce = staticApply staticUnsafeCoerce

    main :: IO ()
    main = do
        let a :: Either String Bool
            a = unstatic remoteTable staticTrue
        print a

        let b :: Either String T
            b = unstatic remoteTable (coerce staticTrue)
        print b

        let c :: Either String T
            c = unstatic remoteTable (staticCoerce staticTrue)
        print c

        putStrLn "done"

The definition of b will result in "Cannot unify Bool and T". For completeness, this example also shows how one might implement staticCoerce if one wished to do so; all this PR does is add a role annotation to static to rule out using coerce.

@mboes
Copy link
Contributor

mboes commented Feb 1, 2016

👍

@edsko
Copy link
Member Author

edsko commented Oct 4, 2016

I've rebased this on the latest master. @mboes , was there a reason why this wasn't merged?

@facundominguez
Copy link
Contributor

I'm guessing nobody cared to press the merge button :)

@facundominguez facundominguez merged commit 6350808 into haskell-distributed:master Oct 4, 2016
@edsko
Copy link
Member Author

edsko commented Oct 5, 2016

Fair enough :) Thanks for merging :)

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

Successfully merging this pull request may close these issues.

3 participants