{-# OPTIONS_GHC -farrows #-} {--- Code for displaying Boolean signals for use with circuits. Taken from Programming with Arrows by John Hughes. ---} module Signal where import qualified Data.List as L class Signal a where showSig :: [a] -> String instance Signal Bool where showSig bs = concat top++"\n"++concat bot++"\n" where (top, bot) = unzip $ zipWith sh (False:bs) bs sh True True = ("__", " ") sh True False = (" ", "|_") sh False True = (" _", "| ") sh False False = (" ", "__") instance (Signal a, Signal b) => Signal (a, b) where showSig xys = showSig (map fst xys) ++ showSig (map snd xys) instance Signal a => Signal [a] where showSig = concat . map showSig . (L.transpose) sig = concat . map (uncurry replicate) testSig = sig [(5,(False,False)), (2,(False,True)), (5,(False,False)), (2,(True,False)), (5,(False,False)), (2,(True,True)), (6,(False,False))]