From d3a9803cf89ea94975934dd8abb18bbc12408a7e Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 6 Dec 2014 00:32:49 +1100 Subject: All newtype stubs now in their own files in their own subdir --- src/Grasp/Types/EdgeLabel.hs | 23 +++++++++++++++++++++ src/Grasp/Types/GEdge.hs | 41 ++++++++++++++++++++++++++++++++++++ src/Grasp/Types/GNode.hs | 37 +++++++++++++++++++++++++++++++++ src/Grasp/Types/IP.hs | 47 ++++++++++++++++++++++++++++++++++++++++++ src/Grasp/Types/Instruction.hs | 32 ++++++++++++++++++++++++++++ 5 files changed, 180 insertions(+) create mode 100644 src/Grasp/Types/EdgeLabel.hs create mode 100644 src/Grasp/Types/GEdge.hs create mode 100644 src/Grasp/Types/GNode.hs create mode 100644 src/Grasp/Types/IP.hs create mode 100644 src/Grasp/Types/Instruction.hs (limited to 'src/Grasp/Types') diff --git a/src/Grasp/Types/EdgeLabel.hs b/src/Grasp/Types/EdgeLabel.hs new file mode 100644 index 0000000..4fbdd27 --- /dev/null +++ b/src/Grasp/Types/EdgeLabel.hs @@ -0,0 +1,23 @@ +module Grasp.Types.EdgeLabel ( + EdgeLabel, + + mk, + + toString + ) where + + + + +newtype EdgeLabel = EdgeLabel String + deriving (Show, Eq) + + + + +mk :: String -> EdgeLabel +mk = EdgeLabel + +toString :: EdgeLabel -> String +toString (EdgeLabel e) = e + diff --git a/src/Grasp/Types/GEdge.hs b/src/Grasp/Types/GEdge.hs new file mode 100644 index 0000000..38ce596 --- /dev/null +++ b/src/Grasp/Types/GEdge.hs @@ -0,0 +1,41 @@ +module Grasp.Types.GEdge ( + GEdge, + + mk, + + toSrc, + toDest, + toLabel, + toLEdge + ) where + + + + +import Grasp.Graph( Node, LEdge ) +import Grasp.Types.EdgeLabel( EdgeLabel ) + + + + +newtype GEdge = GEdge (LEdge EdgeLabel) + deriving (Show, Eq) + + + + +mk :: LEdge EdgeLabel -> GEdge +mk = GEdge + +toSrc :: GEdge -> Node +toSrc (GEdge (x,_,_)) = x + +toDest :: GEdge -> Node +toDest (GEdge (_,y,_)) = y + +toLabel :: GEdge -> EdgeLabel +toLabel (GEdge (_,_,z)) = z + +toLEdge :: GEdge -> LEdge EdgeLabel +toLEdge (GEdge e) = e + diff --git a/src/Grasp/Types/GNode.hs b/src/Grasp/Types/GNode.hs new file mode 100644 index 0000000..92c070e --- /dev/null +++ b/src/Grasp/Types/GNode.hs @@ -0,0 +1,37 @@ +module Grasp.Types.GNode ( + GNode, + + mk, + + toNode, + toInst, + toLNode + ) where + + + + +import Grasp.Graph( Node, LNode ) +import Grasp.Types.Instruction( Instruction ) + + + + +newtype GNode = GNode (LNode Instruction) + deriving (Show, Eq) + + + + +mk :: LNode Instruction -> GNode +mk = GNode + +toNode :: GNode -> Node +toNode (GNode n) = fst n + +toInst :: GNode -> Instruction +toInst (GNode n) = snd n + +toLNode :: GNode -> LNode Instruction +toLNode (GNode n) = n + diff --git a/src/Grasp/Types/IP.hs b/src/Grasp/Types/IP.hs new file mode 100644 index 0000000..c7d3e4b --- /dev/null +++ b/src/Grasp/Types/IP.hs @@ -0,0 +1,47 @@ +module Grasp.Types.IP ( + IP, + + singleton, + empty, + isEmpty, + peek, + push, + pop, + shift + ) where + + + + +import Grasp.Types.GNode( GNode ) + + + + +newtype IP = IP [GNode] + deriving (Eq, Show) + + + + +singleton :: GNode -> IP +singleton n = IP [n] + +empty :: IP +empty = IP [] + +isEmpty :: IP -> Bool +isEmpty (IP p) = (length p == 0) + +peek :: IP -> Maybe GNode +peek (IP p) = if (length p == 0) then Nothing else Just (head p) + +push :: GNode -> IP -> IP +push n (IP p) = IP (n:p) + +pop :: IP -> IP +pop (IP p) = if (length p == 0) then empty else IP (tail p) + +shift :: GNode -> IP -> IP +shift n (IP p) = if (length p == 0) then empty else IP (n:(tail p)) + diff --git a/src/Grasp/Types/Instruction.hs b/src/Grasp/Types/Instruction.hs new file mode 100644 index 0000000..0ff4002 --- /dev/null +++ b/src/Grasp/Types/Instruction.hs @@ -0,0 +1,32 @@ +module Grasp.Types.Instruction ( + Instruction, + + mk, + + toString, + toFloat + ) where + + + + +import Text.Read( readMaybe ) + + + + +newtype Instruction = Instruction String + deriving (Show, Eq) + + + + +mk :: String -> Instruction +mk = Instruction + +toString :: Instruction -> String +toString (Instruction i) = i + +toFloat :: Instruction -> Maybe Float +toFloat (Instruction i) = readMaybe i + -- cgit