1 {-# OPTIONS_GHC -XModalTypes -dcore-lint -XScopedTypeVariables -ddump-types -XTypeFamilies -XNoMonomorphismRestriction #-}
2 module Demo (demo, demo2) where
4 demo z = <[ \y -> ~~z ]>
6 demo2 :: <[ (a,b) ~~> c ]>@d -> <[ () ~~> a ]>@d -> <[ b ~~>c ]>@d
7 demo2 x y = <[ ~~x ~~y ]>
9 swap :: <[ (a,(b,c)) ~~> d ]>@e -> <[ (b,(a,c)) ~~> d ]>@e
10 swap f = <[ \x -> \y -> ~~f y x ]>
12 -- bad = <[ \f -> \x -> f x ]>
14 demo3 x y z q = <[ ~~q (~~x ~~y ~~z) ]>
18 class BitSerialHardwarePrimitives g where
21 <[ not ]> :: <[ (Wire,()) ~~> Wire ]>@g
22 <[ xor ]> :: <[ (Wire,(Wire,())) ~~> Wire ]>@g
23 <[ or ]> :: <[ (Wire,(Wire,())) ~~> Wire ]>@g
24 <[ and ]> :: <[ (Wire,(Wire,())) ~~> Wire ]>@g
25 <[ mux2 ]> :: <[ (Wire,(Wire,(Wire,()))) ~~> Wire ]>@g
26 <[ maj3 ]> :: <[ (Wire,(Wire,(Wire,()))) ~~> Wire ]>@g
27 <[ reg ]> :: <[ (Wire,()) ~~> Wire ]>@g
28 <[ zero ]> :: <[ () ~~> Wire ]>@g
29 <[ one ]> :: <[ () ~~> Wire ]>@g
31 loop :: [Bool] -> <[ () ~~> Wire ]>@g
32 <[ lfsr ]> :: Int -> [ <[ Wire ]>@g ]
33 <[ adder ]> :: <[ (Wire,(Wire,())) ~~> Wire ]>@g
34 fifo :: Int -> <[ (Wire,()) ~~> Wire ]>@g
36 <[ probe ]> :: Int -> <[ (Wire,()) ~~> Wire ]>@g
37 <[ oracle ]> :: Int -> <[ Wire ]>@g
39 xor3 :: forall g . BitSerialHardwarePrimitives g => <[ (Wire,(Wire,(Wire,()))) ~~> Wire ]>@g
40 xor3 = <[ \x -> \y -> \z -> xor (xor x y) z ]>
45 let firstBitMarker = ~~(loop [ i/=0 | i <- [0..31] ])
46 carry_out = reg (mux2 firstBitMarker zero carry_in)
47 carry_in = maj3 carry_out in1 in2
48 in ~~xor3 carry_out in1 in2
54 let sel = ~~(loop [ i >= 32-n | i<-[0..31] ])
55 fifo1 = ~~(fifo (32-n)) input
56 fifo2 = ~~(fifo 32 ) fifo1
57 in mux2 sel fifo1 fifo2
64 let a = ~~(fifo 32) (mux2 load a_in input)
68 e = ~~(fifo 32) (mux2 load e_in d)
74 (~~(rotRight 13) a_in)
75 (~~(rotRight 22) a_in)
78 (~~(rotRight 11) e_in)
79 (~~(rotRight 25) e_in)
86 t2 = adder s0 (maj3 a b c)