aboutsummaryrefslogtreecommitdiffstats
path: root/src/VeriSmith/Circuit/Base.hs
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2019-09-04 20:15:51 +1000
committerYann Herklotz <git@yannherklotz.com>2019-09-04 20:15:51 +1000
commita2b01b92612a098673ff03890e6e8aef4ceb28ea (patch)
tree15cafe6ba47981938552a4b342a56795251aadc5 /src/VeriSmith/Circuit/Base.hs
parentcccb665ebac6e916c4f961eacbe11a9af7d7ceb3 (diff)
downloadverismith-a2b01b92612a098673ff03890e6e8aef4ceb28ea.tar.gz
verismith-a2b01b92612a098673ff03890e6e8aef4ceb28ea.zip
Renaming to VeriSmith
Diffstat (limited to 'src/VeriSmith/Circuit/Base.hs')
-rw-r--r--src/VeriSmith/Circuit/Base.hs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/VeriSmith/Circuit/Base.hs b/src/VeriSmith/Circuit/Base.hs
new file mode 100644
index 0000000..ddcaf65
--- /dev/null
+++ b/src/VeriSmith/Circuit/Base.hs
@@ -0,0 +1,44 @@
+{-|
+Module : VeriSmith.Circuit.Base
+Description : Base types for the circuit module.
+Copyright : (c) 2019, Yann Herklotz Grave
+License : GPL-3
+Maintainer : yann [at] yannherklotz [dot] com
+Stability : experimental
+Portability : POSIX
+
+Base types for the circuit module.
+-}
+
+module VeriSmith.Circuit.Base
+ ( Gate(..)
+ , Circuit(..)
+ , CNode(..)
+ , CEdge(..)
+ )
+where
+
+import Data.Graph.Inductive (Gr, LEdge, LNode)
+import System.Random
+
+-- | The types for all the gates.
+data Gate = And
+ | Or
+ | Xor
+ deriving (Show, Eq, Enum, Bounded, Ord)
+
+-- | Newtype for the Circuit which implements a Graph from fgl.
+newtype Circuit = Circuit { getCircuit :: Gr Gate () }
+
+-- | Newtype for a node in the circuit, which is an 'LNode Gate'.
+newtype CNode = CNode { getCNode :: LNode Gate }
+
+-- | Newtype for a named edge which is empty, as it does not need a label.
+newtype CEdge = CEdge { getCEdge :: LEdge () }
+
+instance Random Gate where
+ randomR (a, b) g =
+ case randomR (fromEnum a, fromEnum b) g of
+ (x, g') -> (toEnum x, g')
+
+ random = randomR (minBound, maxBound)