1 module Dcore ( int_to_str , list_to_str , str_to_int , str_to_list 2 , encode ) 3 where 4 5 import Sub_Core1 6 7 import Sub_Core2 8 9 import Sub_Core3 10 11 import Sub_Core4 12 13 import Vtslib 14 15 import Core_datatype 16 17 int_to_str :: Int -> String 18 19 int_to_str i 20 | i < 256 = [ toEnum 0 , toEnum i ] 21 | i < 65536 = [] -- [ toEnum ((i `div` 256) `rem` 256) , toEnum (i `rem` 256) ] 22 | otherwise = error "Bind" -- ** exn 23 24 25 26 27 28 list_to_str obj_to_str_fn objL 29 = int_to_str (length objL) ++ concat (map obj_to_str_fn objL) 30 31 32 33 34 str_to_int :: [Int] -> (Int, [Int]) 35 36 str_to_int ( ch1 : ch2 : s ) 37 = (ch1*256+ch2,s) 38 39 40 41 42 43 str_to_list :: ([Int] -> (b, [Int])) -> [Int] -> ([b], [Int]) 44 45 str_to_list str_to_fn s 46 = f i s1 47 where 48 f 0 s = ([],s) 49 f i s = (obj:objL,s2) 50 where 51 (obj,s1) = str_to_fn s 52 (objL,s2) = f (i-1) s1 53 (i, s1) = str_to_int s 54 55 56 57 58 encode :: (Eq b) => b -> [b] -> Int 59 60 encode obj objL 61 = enc 0 objL 62 where 63 enc i [] = error "Encode" -- ** exn 64 enc i (obj1:objL) 65 | obj == obj1 = i 66 | otherwise = enc (i+1) objL 67