Last active
August 12, 2018 06:37
-
-
Save hardvain/d6b40b63cb3da343d76fe49f1bd2b182 to your computer and use it in GitHub Desktop.
SVG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
• Couldn't match type ‘Circle’ with ‘Line’ | |
Expected type: Tree Line | |
Actual type: Tree Circle | |
• In the expression: Node (Circle (20, 30) 50) [] | |
In the second argument of ‘Node’, namely | |
‘[Node (Circle (20, 30) 50) []]’ | |
In the expression: | |
Node (Line (100, 100) (30, 60)) [Node (Circle (20, 30) 50) []] | |
| | |
11 | sampleTree = Node (Line (100,100) (30,60)) [Node (Circle (20,30) 50) []] | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SvgNode a where | |
toSVG :: a -> String | |
element :: a -> String | |
instance SvgNode Circle where | |
toSVG (Circle (x,y) radius) = "<circle cx='" ++ show x ++ "' cy='" ++ show y ++ "' r='" ++ show radius ++ "' stroke='red' fill='transparent' stroke-width='5'>" | |
element _ = "circle" | |
instance SvgNode Rectangle where | |
toSVG (Rectangle (x,y) width height) = "<rect x='" ++ show x ++ "' y='" ++ show y ++ "' width='" ++ show width ++ "' height='" ++ show height ++ "' stroke='black' fill='transparent' stroke-width='5'>" | |
element _ = "rectangle" | |
-- this is where I get the issue. I want to create a tree of SVGNode with both Line & Circle | |
sampleTree :: forall a. SvgNode a => Tree a | |
sampleTree = Node (Line (100,100) (30,60)) [Node (Circle (20,30) 50) []] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Tree a = Empty | Node a [Tree a] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment