5 class (Eq a, Show{-was:Text-} a, Num a) => Signal a where
8 zerO, one, initial :: a
11 tt2 :: TT2 -> a -> a -> a
13 con10, buf, inv, con11 :: a -> a
15 con20, and2, nimp, id21 :: a -> a -> a
16 nimp', id22, xor, or2 :: a -> a -> a
17 nor2, equ2, inv22, imp' :: a -> a -> a
18 inv21, imp, nand2, con21 :: a -> a -> a
19 and3, or3, nand3, nor3 :: a -> a -> a -> a
20 and4, or4, nand4, nor4 :: a -> a -> a -> a -> a
46 nand3 a b c = nand2 a (nand2 b c)
47 nor3 a b c = nor2 a (nor2 b c)
49 and4 a b c d = (a*b)*(c*d)
50 or4 a b c d = (a+b)+(c+d)
51 nand4 a b c d = nand2 (nand2 a b) (nand2 c d)
52 nor4 a b c d = nor2 (nor2 a b) (nor2 c d)
54 class (Signal a) => Lattice a where
55 bot, top, weakZero, weakOne :: a
59 class (Signal a) => Static a where
62 showStaticSig :: a -> String
64 class (Signal a) => Dynamic a where
67 class (Lattice a, Static a) => Log a where
70 class (Lattice a, Dynamic a) => Sig a where
73 data Stream a = Snil | Scons a (Stream a) deriving (Eq,Show{-was:Text-})
75 shead :: Stream a -> a
76 shead (Scons x xs) = x
78 stail :: Stream a -> Stream a
79 stail (Scons x xs) = xs
81 snull :: Stream a -> Bool
83 snull (Scons x xs) = False
85 smap :: (a->b) -> Stream a -> Stream b
87 smap f (Scons x xs) = Scons (f x) (smap f xs)
89 stake, sdrop :: Int -> Stream a -> Stream a
92 --should be: stake (i+1) (Scons x xs) = Scons x (stake i xs)
93 stake i (Scons x xs) | i < 0 = error "Signal.stake: < 0"
94 | otherwise = Scons x (stake (i-1) xs)
97 --should be:sdrop (i+1) (Scons x xs) = sdrop i xs
98 sdrop i (Scons x xs) | i < 0 = error "Signal.sdrop: < 0"
99 | otherwise = sdrop i xs
101 smap2 :: (a->b->c) -> Stream a -> Stream b -> Stream c
108 Scons b bs' -> Scons (f a b) (smap2 f as' bs')
110 srepeat :: (Static a) => a -> Stream a
111 srepeat x = xs where xs = Scons x xs
113 stream :: [a] -> Stream a
115 stream (x:xs) = Scons x (stream xs)
117 instance (Signal a, Static a) => Dynamic (Stream a) where
118 latch xs = Scons initial xs
119 dff xs = Scons initial xs
121 instance (Lattice a, Static a) => Lattice (Stream a) where
124 weakZero = srepeat weakZero
125 weakOne = srepeat weakOne
129 instance (Signal a, Static a) => Signal (Stream a) where
135 instance (Lattice a, Static a) => Sig (Stream a) where
136 dumSig = bot -- ??? shouldn't be necessary, check compiler
138 instance (Static a) => Num (Stream a) where
143 abs = error "abs not defined for Signals"
144 signum = error "signum not defined for Signals"
145 fromInteger = error "fromInteger not defined for Signals"