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

Commit 957c257

Browse files
Merge pull request #16 from haskell-distributed/fd/no-rtt-check
Remove dynamic type check in Static Binary instance.
2 parents 76ab3e6 + 0bbb55c commit 957c257

File tree

1 file changed

+6
-41
lines changed

1 file changed

+6
-41
lines changed

src/Control/Distributed/Static.hs

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,6 @@
88
-- all distributed nodes are using the same 'RemoteTable'). In this module
99
-- we implement this mimickry and various extensions.
1010
--
11-
-- [Dynamic type checking]
12-
--
13-
-- The paper stipulates that 'Static' values should have a free 'Binary'
14-
-- instance:
15-
--
16-
-- > instance Binary (Static a)
17-
--
18-
-- This however is not (runtime) type safe: for instance, what would be the
19-
-- behaviour of
20-
--
21-
-- > f :: Static Int -> Static Bool
22-
-- > f = decode . encode
23-
--
24-
-- For this reason we work only with 'Typeable' terms in this module, and
25-
-- implement runtime checks
26-
--
27-
-- > instance Typeable a => Binary (Static a)
28-
--
29-
-- The above function 'f' typechecks but throws an exception if executed. The
30-
-- type representation we use, however, is not the standard
31-
-- 'Data.Typeable.TypeRep' from "Data.Typeable" but
32-
-- 'Data.Rank1Typeable.TypeRep' from "Data.Rank1Typeable". This means that we
33-
-- can represent polymorphic static values (see below for an example).
34-
--
35-
-- Since the runtime mapping ('RemoteTable') contains values of different types,
36-
-- it maps labels ('String's) to 'Data.Rank1Dynamic.Dynamic' values. Again, we
37-
-- use the implementation from "Data.Rank1Dynamic" so that we can store
38-
-- polymorphic dynamic values.
39-
--
4011
-- [Compositionality]
4112
--
4213
-- Static values as described in the paper are not compositional: there is no
@@ -252,14 +223,13 @@ import Control.DeepSeq (NFData(rnf), force)
252223
import Data.Rank1Dynamic (Dynamic, toDynamic, fromDynamic, dynApply)
253224
import Data.Rank1Typeable
254225
( Typeable
255-
, typeOf
256226
, ANY1
257227
, ANY2
258228
, ANY3
259229
, ANY4
260-
, isInstanceOf
261230
#if __GLASGOW_HASKELL__ >= 710
262231
, TypeRep
232+
, typeOf
263233
#endif
264234
)
265235

@@ -322,14 +292,9 @@ newtype Static a = Static StaticLabel
322292
instance NFData (Static a) where
323293
rnf (Static s) = rnf s
324294

325-
instance Typeable a => Binary (Static a) where
326-
put (Static label) = putStaticLabel label >> put (typeOf (undefined :: a))
327-
get = do
328-
label <- getStaticLabel
329-
typeRep <- get
330-
case typeOf (undefined :: a) `isInstanceOf` typeRep of
331-
Left err -> fail $ "Static.get: type error: " ++ err
332-
Right () -> return (Static label)
295+
instance Binary (Static a) where
296+
put (Static label) = putStaticLabel label
297+
get = Static <$> getStaticLabel
333298

334299
-- We don't want StaticLabel to be its own Binary instance
335300
putStaticLabel :: StaticLabel -> Put
@@ -446,8 +411,8 @@ unstatic rtable (Static label) = do
446411
data Closure a = Closure !(Static (ByteString -> a)) !ByteString
447412
deriving (Eq, Ord, Typeable, Show)
448413

449-
instance Typeable a => Binary (Closure a) where
450-
put (Closure dec env) = put dec >> put env
414+
instance Binary (Closure a) where
415+
put (Closure st env) = put st >> put env
451416
get = Closure <$> get <*> get
452417

453418
#if MIN_VERSION_bytestring(0,10,0)

0 commit comments

Comments
 (0)