1 module FAmap 2 3 ( mapBDFA 4 , mapTNFA 5 ) 6 7 where 8 9 import Set 10 import FiniteMap 11 12 import Options 13 14 import Stuff 15 16 import TA 17 import FAtypes 18 19 mapBDFA :: (Ord a, Ord b) => Opts -> (a -> b) -> BDFA a -> BDFA b 20 -- f must be injective 21 mapBDFA opts f (BDFA cons all starts moves) = 22 let h = listToFM [(a, f a)|a <- setToList all] 23 r = lookupWithDefaultFM h (error "mapBDFA") 24 all' = mapSet r all 25 starts' = mapSet r starts 26 moves' = listToFM [ (mksterm (stcon t) (map r (stargs t)), r v) 27 | (t, v) <- fmToList moves ] 28 in BDFA cons all' starts' moves' 29 30 mapTNFA :: (Ord a, Ord b) => Opts -> (a -> b) -> TNFA a -> TNFA b 31 -- f must be injective 32 mapTNFA opts f (TNFA cons all starts moves) = 33 let h = listToFM [ (a, f a) | a <- setToList all] 34 r = f -- lookupWithDefaultFM h (error "mapTNFA") 35 all' = mapSet r all 36 starts' = mapSet r starts 37 moves' = listToFM 38 [ (r v, mapSet (\ t -> mksterm (stcon t) (map r (stargs t))) ts ) 39 | (v, ts) <- fmToList moves ] 40 in TNFA cons all' starts' moves' 41