Changeset 8699 for src/DrIFT/YAML.hs
- Timestamp:
- 01/16/06 13:08:43 (3 years ago)
- Files:
-
- 1 modified
-
src/DrIFT/YAML.hs (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/DrIFT/YAML.hs
r8694 r8699 9 9 import UTF8 10 10 import Data.Typeable 11 import Control.Exception 11 12 12 13 type YAMLClass = String … … 16 17 showYaml :: YAML a => a -> IO String 17 18 showYaml x = do 18 rv <- emitYaml =<< asYAML x 19 node <- asYAML x 20 rv <- emitYaml node 19 21 case rv of 20 22 Left e -> error e … … 23 25 class Typeable a => YAML a where 24 26 asYAML :: a -> IO YamlNode 25 asYAML x | ty == "()" = return nilNode 26 | otherwise = return $ mkTagNode (tagHs ty) YamlNil 27 where 28 ty = (reverse (takeWhile (/= '.') (reverse (show (typeOf x))))) 27 asYAML x = do 28 ty <- Control.Exception.handle (const $ return "()") $ 29 evaluate (reverse (takeWhile (/= '.') (reverse (show (typeOf x))))) 30 return $ case ty of 31 "()" -> nilNode 32 _ -> mkTagNode (tagHs ty) YamlNil 29 33 30 34 asYAMLseq :: YAMLClass -> [IO YAMLVal] -> IO YamlNode … … 48 52 tagHs :: YAMLClass -> String 49 53 tagHs = ("tag:hs:" ++) 54 55 instance YAML () where 50 56 51 57 instance YAML Int where
