From 845c5043f321365c7751eb5d8377ca62869f9f4f Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 17 May 2014 14:10:32 +1000 Subject: mul instruction complete --- src/Grasp/Interpreter.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs index 8cfe502..7d38ebd 100644 --- a/src/Grasp/Interpreter.hs +++ b/src/Grasp/Interpreter.hs @@ -218,7 +218,13 @@ retI g ip = return (g,ip) addI :: GraspProgram -> IP -> IO (GraspProgram, IP) -addI g ip = do +addI = addmulI sum + +mulI :: GraspProgram -> IP -> IO (GraspProgram, IP) +mulI = addmulI product + +addmulI :: ([Float] -> Float) -> GraspProgram -> IP -> IO (GraspProgram, IP) +addmulI f g ip = do let node = fst . head $ ip edges = Graph.out g node @@ -229,7 +235,7 @@ addI g ip = do g' <- case argL of x | not (all isFloat x) -> error ("Instruction " ++ (show node) ++ " has non numeric arguments") - x -> let s = sum . map (read :: String -> Float) $ x + x -> let s = f . map (read :: String -> Float) $ x in return (foldl' (\gr n -> reLabel gr n (show s)) g outN) ip' <- updateIP ip nextLN @@ -238,9 +244,6 @@ addI g ip = do -mulI :: GraspProgram -> IP -> IO (GraspProgram, IP) -mulI g ip = return (g,ip) - subI :: GraspProgram -> IP -> IO (GraspProgram, IP) subI g ip = return (g,ip) -- cgit