aboutsummaryrefslogtreecommitdiffstats
path: root/src/Main.hs
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-10-29 19:36:28 +0000
committerYann Herklotz <ymherklotz@gmail.com>2018-10-29 19:36:28 +0000
commit4c0801886a489e9c9529c786f1122a8e71f46f5d (patch)
tree9bd571feb440d877fc1e4af3e46250514cd253b8 /src/Main.hs
parent796ea5d8f5d6ea422fbb1fbe29621abd7a9f2161 (diff)
downloadverismith-4c0801886a489e9c9529c786f1122a8e71f46f5d.tar.gz
verismith-4c0801886a489e9c9529c786f1122a8e71f46f5d.zip
Simple visualization
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs25
1 files changed, 7 insertions, 18 deletions
diff --git a/src/Main.hs b/src/Main.hs
index ffbef9a..c52ad16 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -4,18 +4,12 @@ import Data.Bits
import Test.QuickCheck hiding ((.&.))
import Data.GraphViz
import Data.Graph.Inductive.Example (clr479, dag4)
-import Data.Text.Lazy
-import Data.GraphViz.Printing
import Data.Graph.Inductive.Graph
import Data.Graph.Inductive.PatriciaTree
type Input = Bool
-data Gate = And
- | Or
- | Xor
- | Nand
- | Nor
+data Gate = Nand
deriving (Show)
data Circuit a = In a
@@ -23,7 +17,7 @@ data Circuit a = In a
deriving (Show)
instance Arbitrary Gate where
- arbitrary = elements [And, Or, Xor, Nand, Nor]
+ arbitrary = return Nand
instance (Arbitrary a) => Arbitrary (Circuit a) where
arbitrary = do
@@ -34,24 +28,19 @@ instance (Arbitrary a) => Arbitrary (Circuit a) where
eval :: (Bits a) => Circuit a -> a
eval (In val) = val
-eval (Node And c1 c2) = eval c1 .&. eval c2
-eval (Node Or c1 c2) = eval c1 .|. eval c2
-eval (Node Xor c1 c2) = eval c1 `xor` eval c2
eval (Node Nand c1 c2) = complement $ eval c1 .&. eval c2
-eval (Node Nor c1 c2) = complement $ eval c1 .|. eval c2
visualize :: (Show a) => Circuit a -> Gr String String
visualize circ =
- uncurry mkGraph $ graph Nothing 0 ([], []) circ
+ graph Nothing 0 (empty :: Gr String String) circ
where
- graph parent nl (l, e) circ =
+ graph parent nl graph circ =
+ let newNode str graph = (head $ newNodes 1 graph, str) in
case (parent, circ) of
(Nothing, (In val)) ->
- ((nl, "In: " ++ show val) : l, e)
- (Just par, (In val)) ->
- ((nl, "In: " ++ show val) : l, (par, nl, "") : e)
+ insNode (newNode "IN" graph) graph
_ ->
- ([], [])
+ graph
main :: IO ()
--main = sample (arbitrary :: Gen (Circuit Input))