, . , . :
data BinaryDict a = BinaryDict
{ bdEncode :: a -> ByteString
, bdDecode :: ByteString -> a
}
:
closurePure :: (Typeable a) => BinaryDict a -> a -> Closure a
:
closurePure bdict = closure (staticPtr (static (bdDecode bdict))) . bdEncode bdict
, , , , static . BinaryDict willy nilly, , , . :
closurePure :: (Typeable a) => Static (BinaryDict a) -> a -> Closure a
Binary . , , . , , .
, , , . ( , reflection? ). , , , ( ).
, , (déjà vu?).
class c => StaticConstraint c where
staticConstraint :: StaticPtr (Dict c)
instance StaticConstraint (Show Int) where
staticConstraint = static Dict
-- a handful more lines...
, ( ), , , :
closurePure :: (Typeable a, Binary a) => StaticPtr (ByteString -> a) -> a -> Closure a
closurePure decodePtr = closure (staticPtr decodePtr) . encode
someClosure :: Closure Int
someClosure = closurePure (static decode) 42
, static " ", , - , , Binary Int .
, {-# LANGUAGE CPP #-}
someClosure :: Closure Int
someClosure = PURE 42
, - Haskell Segmentation fault (core dumped) , .