| 9 | | class (Typeable a) => Class a where |
| 10 | | iType :: a -> Type |
| 11 | | iType = const $ mkType "Scalar" |
| 12 | | fetch :: a -> Eval VScalar |
| 13 | | store :: a -> VScalar -> Eval () |
| | 13 | instance ScalarClass IScalar where |
| | 14 | scalar_fetch = liftSTM . readTVar |
| | 15 | scalar_store = (liftSTM .) . writeTVar |
| | 16 | |
| | 17 | instance ScalarClass IScalarLazy where |
| | 18 | scalar_iType = const $ mkType "Scalar::Lazy" |
| | 19 | scalar_fetch = return . maybe undef id |
| | 20 | scalar_store _ v = retConstError v |
| | 21 | |
| | 22 | instance ScalarClass IScalarCwd where |
| | 23 | scalar_iType = const $ mkType "Scalar::Cwd" |
| | 24 | scalar_fetch _ = do |
| | 25 | str <- liftIO $ getCurrentDirectory |
| | 26 | return $ VStr str |
| | 27 | scalar_store _ val = do |
| | 28 | str <- fromVal val |
| | 29 | tryIO () $ setCurrentDirectory str |
| | 30 | |
| | 31 | instance ScalarClass VScalar where |
| | 32 | scalar_iType = const $ mkType "Scalar::Const" |
| | 33 | scalar_fetch (VRef ref) = readRef ref |
| | 34 | scalar_fetch v = return v |
| | 35 | scalar_store _ v = retConstError v |
| | 36 | |