f1 (x,y) = nand2(x,y) g1 (x,y) = x+y
f2 x y = nand2(x,y) g2 x y = x+y
map (g2 3) [4,5,6] = [7,8,9]
f1 :: (Bit,Bit) -> Bit f1 (x,y) = nand2(x,y) g1 :: (Int,Int) -> Int g1 (x,y) = x+y f2 :: Bit -> (Bit -> Bit) f2 x y = nand2(x,y) g2 :: Int -> Int -> Int g2 x y = x+y
g2 3 :: Int->Int
map (g2 3) :: [Int]->[Int]
(Bit,Bit)->Bit

serial ((circ1,circ2),inp) = out
where
mid = circ1 inp
out = circ2 mid
serial (circ1,circ2) inp = out
where
mid = circ1 inp
out = circ2 mid
serial circ1 circ2 inp = out
where
mid = circ1 inp
out = circ2 mid
circ1 ->- circ2 = serial circ1 circ2
c1 ->- c2 ->- c3 -> c4

par f g (inp1,inp2) = (out1,out2)
where
out1 = f inp1
out2 = g inp2
f -|- g = par f g
map function
map f [x1,x2,...,xn] = [f x1,f x2,...,f xn]
row function

bad inp = out
where
out = nand2(inp,out)
simulate bad low
simulate bad high
*** Exception: combinational loop
out <= a nand b;
out <= a nand b after 4ns;
delay init s
s by one time unit.
init.
nand2D = nand2 ->- delay low
good a = out
where
out = nand2D(a,out)
simulate good high
simulateSeq good [high,high,high,high]
low5 = replicate 5 low high5 = replicate 5 high
simulateSeq good (high5++low5++high5)
++ joins two lists
zipp :: ([a],[b]) -> [(a,b)]
unzipp :: [(a,b)] -> ([a],[b])
replicate :: Int -> a -> [a]
++ :: [a] -> [a] -> [a]
map :: (a->b) -> ([a] -> [b])
[]: the empty list
x : xs: adding one more element to the
front of a list
3:[4,5,6] = [3,4,5,6]
[3,4,5,6] is just a shorthand for
3:4:5:6:[]
replicate 3 low work?
replicate 3 low = low : replicate 2 low
= low : low : replicate 1 low
= low : low : low : replicate 0 low
= low : low : low : []
= [low,low,low]
replicate defined?
replicate 0 x = [] replicate n x = x : replicate (n-1) x
sum sums a list of numbers
sum :: [Int] -> Int
sum [] = 0
sum [7,5,3,6] = 7+5+3+6 = 21
sum work?
sum [7,5,3,6] = 7 + sum [5,3,6]
= 7 + 5 + sum [3,6]
= 7 + 5 + 3 + sum [6]
= 7 + 5 + 3 + 6 + sum []
= 7 + 5 + 3 + 6 + 0
= 21
sum defined?
sum [] = 0 sum (x : xs) = x + sum xs
minimum finds the minimum
number in a list
minimum [7,3,6] = 3
minimum [] = ?? we want to leave it undefined
minimum [7] = 7
min2 :: (Int,Int) -> Int
minimum work?
minimum [7,3,6] = min2(7,minimum [3,6])
= min2(7,min2(3,minimum [6]))
= min2(7,min2(3,6))
= min2(7,3)
= 3
minimum defined?
minimum [] = error "minimum of empty list" minimum [x] = x minimum (x:xs) = min2(x,minimum xs)
high if the number is zero (all bits are zero).
zero_detect :: [Bit] -> Bit