| | 13 | instance Coercible P PureStr where |
| | 14 | asStr = return . cast |
| | 15 | |
| | 16 | class (Monad m, Functor m, Eq a, Data a, Typeable a) => Coercible 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 | asList :: a -> Maybe (m PureList) |
| | 26 | asList _ = Nothing -- default = do not flatten |
| | 27 | asNative :: a -> m ValNative |
| | 28 | asNative = fmap (NBuf . cast) . asStr |
| | 29 | |