Posts

Showing posts from July 24, 2008

Debugging Haskell: LFG, AVM → DAG

Image
A few days ago I had to do some debugging in Haskell while writing a function to draw directed acyclic graphs of attribute value matrices from LFG F-structures. UnsafePerformIO was great help there. I did most of this during a machine translation lecture given by Kurt Eberle of lingenio . Here are the debugging functions: deb1 :: Show a ⇒ a → a deb1 a = unsafePerformIO (print a >> return a) deb2 :: Show a ⇒ String → a → a deb2 msg a = unsafePerformIO (putStrLn (((msg ++) . show) a) >> return a) deb3 :: (Show a, Show b) ⇒ (a → Bool) → b → a → a deb3 p b a = unsafePerformIO $ esc p b a where esc p b a | p a = putStr ((show b) ++ (show a)) >> return a | otherwise = return a cond = (== "^OBL") dobj = deb3 cond And here is how I used them in context: core :: Integer → String → [(Integer,String)] → AVM → (String,[(Integer,String)],Integer) core i s ls (M att (A val)) = (s ++ x i ++ " [label=\"" ++ dobj s att ++ "\&quo