From 01852574444103473609acfea9bc80621c12f521 Mon Sep 17 00:00:00 2001 From: Robbie Gleichman Date: Sun, 18 Dec 2016 21:15:59 -0800 Subject: [PATCH] Fix some instances of <$> not being converted to fmap. --- app/Translate.hs | 2 +- test/UnitTests.hs | 18 ++++++++++++++---- todo.txt | 5 +++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/Translate.hs b/app/Translate.hs index 2e0354e..2e11dd6 100644 --- a/app/Translate.hs +++ b/app/Translate.hs @@ -205,7 +205,6 @@ evalInfixApp :: EvalContext -> Exp -> QOp -> Exp -> State IDState (SyntaxGraph, evalInfixApp c e1 op e2 = case op of QVarOp (UnQual (Symbol sym)) -> case sym of "$" -> evalExp c (App e1 e2) - "<$>" -> evalExp c $ App (App (makeVarExp "fmap") e1) e2 "." -> fmap Right <$> evalCompose c (e1 : simplifyCompose e2) _ -> defaultCase _ -> defaultCase @@ -237,6 +236,7 @@ simplifyExp e = case removeParen e of InfixApp exp1 (QVarOp (UnQual (Symbol "$"))) exp2 -> App exp1 exp2 -- Don't convert compose to apply InfixApp _ (QVarOp (UnQual (Symbol "."))) _ -> e + App (Var (UnQual (Symbol "<$>"))) arg -> App (makeVarExp "fmap") arg InfixApp exp1 op exp2 -> App (App (qOpToExp op) exp1) exp2 LeftSection exp1 op -> App (qOpToExp op) exp1 x -> x diff --git a/test/UnitTests.hs b/test/UnitTests.hs index ac370df..c13736e 100644 --- a/test/UnitTests.hs +++ b/test/UnitTests.hs @@ -354,14 +354,24 @@ lambdaTests = TestList [ ] ] --- Yes, the commas get their own line -translateUnitTests :: Test -translateUnitTests = TestList [ - TestLabel "fmapTest" $ assertEqualSyntaxGraphs [ +fmapTests :: Test +fmapTests = TestList [ + assertEqualSyntaxGraphs [ "y = fmap f x", "y = f <$> x" ] , + assertEqualSyntaxGraphs [ + "y = f1 (fmap f2 (f3 x))", + "y = f1 $ f2 <$> f3 x" + ] + ] + +-- Yes, the commas get their own line +translateUnitTests :: Test +translateUnitTests = TestList [ + TestLabel "fmapTest" fmapTests + , TestLabel "applyTests" applyTests , TestLabel "composeApplyTests" composeApplyTests diff --git a/todo.txt b/todo.txt index 8dc8288..f2b2ee8 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,5 @@ -- TODO Now -- +Case icon that can embed literals Consider adding binding variable names to the lambda icon and match icon. Don't display the name if it is only one character. @@ -10,11 +11,11 @@ Fix the arrowheads being too big for SyntaxGraph drawings. -- Visual todos: Draw bounding boxes for lambdas (use dashed lines) -Case icon that can embed literals + -- Make an icon font/library with labeled ports. E.g. the apply icon would have text labels "function", "result", "arg 0", "arg 1", etc. -- Don't rotate text and nested icons, give them rectangular bounding boxes in GraphViz. (Perhaps use a typeclass for isRotateAble) -- Give lines a black border to make line crossings easier to see. --- Let lines connect to ports in multiple locations (e.g. case value, or guard result) +-- Let lines connect to ports in multiple locations (e.g. guard result) -- Use different line styles (e.g. dashed, solid, wavy) in addition to colors Use diagrams to shrink the drawing until icons start overlapping.