| 15 | | |
| 16 | | class (Monad m, Functor m, Eq a, Data a, Typeable a) => ICoercible m a | a -> m where |
| 17 | | asBit :: a -> m PureBit |
| 18 | | asBit _ = return True |
| 19 | | asInt :: a -> m PureInt |
| 20 | | asInt x = fail $ "coerce fail: " ++ (show $ typeOf x) ++ " to PureInt" |
| 21 | | asNum :: a -> m PureNum |
| 22 | | asNum x = fail $ "coerce fail: " ++ (show $ typeOf x) ++ " to PureNum" |
| 23 | | asStr :: a -> m PureStr |
| 24 | | asStr x = return (cast "<opaque>") -- XXX wrong |
| 25 | | -- "$item = VAL" |
| 26 | | asItem :: a -> Maybe (m Val) |
| 27 | | asItem _ = Nothing -- default = do nothing (for Scalar this would return its content) |
| 28 | | -- "@list = VAL" |
| 29 | | asList :: a -> Maybe (m PureList) |
| 30 | | asList _ = Nothing -- default = do nothing (for Scalar this would return its content wrapped in a 1-seq) |
| 31 | | asNative :: a -> m ValNative |
| 32 | | asNative = fmap (NBuf . cast) . asStr |
| 33 | | |
| | 15 | -} |