Circuit arrows
Simple update of the circuit arrows from Programming with Arrows to work with the modern Arrow libraries.
module Circuits where
import Control.Arrow
import Data.List
class ArrowLoop a => ArrowCircuit a where
delay :: b -> a b b
nor :: Arrow a => a (Bool,Bool) Bool
= arr (not.uncurry (||))
nor
flipflop :: ArrowCircuit a => a (Bool,Bool) (Bool,Bool)
= loop (arr (\((a,b),(c,d)) -> ((a,d),(b,c))) >>>
flipflop *** nor >>>
nor False,True) >>>
delay (id &&& arr id)
arr
class Signal a where
showSignal :: [a] -> String
instance Signal Bool where
= concat top++"\n"++concat bot++"\n"
showSignal bs where (top,bot) = unzip (zipWith sh (False:bs) bs)
True True = ("__"," ")
sh True False = (" ","|_")
sh False True = (" _","| ")
sh False False = (" ","__")
sh
instance (Signal a,Signal b) => Signal (a,b) where
= showSignal (map fst xys)++showSignal (map snd xys)
showSignal xys
instance Signal a => Signal [a] where
= concatMap showSignal . transpose
showSignal
sig :: [(Int, a)] -> [a]
= concatMap (uncurry replicate)
sig
flipflopInput :: [(Bool, Bool)]
= sig
flipflopInput 5,(False,False)),(2,(False,True)),(5,(False,False)),
[(2,(True,False)),(5,(False,False)),(2,(True,True)),
(6,(False,False))] (