From 4b0fd5fe80607e1487659acfdc51cc95a1b7effe Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Fri, 2 May 2014 03:32:12 +1000 Subject: Grasp program isomorphic comparison half done --- src/Grasp/Parser.hs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src') diff --git a/src/Grasp/Parser.hs b/src/Grasp/Parser.hs index e7c920d..1ddbb94 100644 --- a/src/Grasp/Parser.hs +++ b/src/Grasp/Parser.hs @@ -1,7 +1,10 @@ module Grasp.Parser ( GraspProgram(..), + GraspData(..), parseGrasp, + nodesWithName, + iso, dup ) where @@ -26,6 +29,14 @@ type StrLNode a = (String,a) type StrLEdge a = (String,String,a) +type GraspData = ([StrLNode String],[StrLEdge String]) + + + +instance (Ord a, Ord b) => Eq (Gr a b) where + a == b = ((sort . Graph.labNodes $ a) == (sort . Graph.labNodes $ b)) && + ((sort . Graph.labEdges $ a) == (sort . Graph.labEdges $ b)) + @@ -88,6 +99,28 @@ constructGraph = uncurry Graph.mkGraph +nodesWithName :: GraspProgram -> String -> [LNode String] +nodesWithName g s = [] + + + +normalise :: GraspData -> ([LNode String],[LEdge String]) +normalise (n,e) = ([],[]) + + + +iso :: GraspProgram -> GraspProgram -> Bool +iso a b = + let f (x,y) = (show x, y) + g (x,y,z) = (show x, show y, z) + + -- converts a grasp program into grasp data + h x = ((map f) . Graph.labNodes $ x, (map g) . Graph.labEdges $ x) + + in (constructGraph . normalise . h $ a) == (constructGraph . normalise . h $ b) + + + dup :: (Eq a) => [a] -> Maybe a dup x = let dup' [] _ = Nothing -- cgit