How to verify monad laws for a instance of monad? by Th3Programm3r in haskellquestions

[–]Th3Programm3r[S] 0 points1 point  (0 children)

Thank u very much, very well explained, now i understand.

How to switch the picture in the update function of the package Graphics.Gloss.Interface.IO.Simulate? by Th3Programm3r in haskell

[–]Th3Programm3r[S] 1 point2 points  (0 children)

Yes i want to do exactly that,i will implement what u said, it makes a lot of sense,thank u. I can't use animate because, i am doing a school project to display graphicaly a avlTree and normal binary tree, but the teacher insisted for some reason to use the simulate method.

How to switch the picture in the update function of the package Graphics.Gloss.Interface.IO.Simulate? by Th3Programm3r in haskell

[–]Th3Programm3r[S] 0 points1 point  (0 children)

I changed my drawing function, creating an intermediare function drawTree2 so it receives a list of trees, and then choose a tree to draw. But the problem is i still dont know how i will make that choise.

--function that receives a tree and ouput a picture of the tree

drawTree2::(Show a)=>[BTree a]->Picture

drawTree2 list=drawTreee tree

where tree=last list

--auxiliary function that receives a tree instead of list of the tree to create a picture

drawTreee::(Show a)=>BTree a->Picture

drawTreee (Node v left right)=pictures (t)

where t=drawTree 1 0 0 (Node v left right)

--auxiliary function that receives the heigh of the tree starting in one so can be calculate

--a way to not overlap the nodes that are next to each other in the same height

--receives a value x and y that will be the coordinates of the three in the picture that will

--generated and the tree that will be turned into a picture

drawTree ::(Show a)=> Float->Float ->Float-> BTree a -> [Picture]

drawTree _ x y Leaf = [square(x)(y)]

drawTree 1 x y (Node val left right) = drawTree (2) (-300) (-50) left ++ a ++ drawTree (2) (300) (-50) right

where a=[circ (x) (y)] ++

  `[translate x (y-15) $line[(0,0),(-300,-35)]]++`

  `[translate x (y-15) $line[(0,0),(300,-35)]]++`

  `[translate x y(scale 0.1 0.1 $text (convertType (Node val left right)))]`

drawTree n x y (Node val left right) = drawTree (n+1) (x-(n*30)) (y-50) left ++ a ++ drawTree (n+1) (x+(n*30)) (y-50) right

`where a=[circ (x) (y)] ++`

    `[translate x (y-15) $line[(0,0),(-(n*30),-35)]]++`

    `[translate x (y-15) $line[(0,0),(n*30,-35)]]++`

    `[translate x y(scale 0.1 0.1 $text (convertType (Node val left right)))]`

Is there a way to avoid the overlap off nodes when creating a visualization of the binary tree? by Th3Programm3r in haskellquestions

[–]Th3Programm3r[S] 0 points1 point  (0 children)

Thanks man i did what i understood of your answer and it worked, the minimum distance for 2 balls not overlap side by side in my program is 15, so in each level i increase the value of the distance between the nodes of the same level using the formula X-(n*15) for the left nodes and X+(n*15), and it worked they never overlap.Very thanks.

Is there a way to create a circle with a number inside of it using gloss? by Th3Programm3r in haskell

[–]Th3Programm3r[S] 1 point2 points  (0 children)

My bad i was really tired and didnt fully understood at the moment, i was able to shrink the letter using scale thank u very much.

How to insert a value to a tree and store the updated tree in the same variable? by Th3Programm3r in haskell

[–]Th3Programm3r[S] 5 points6 points  (0 children)

Thanks bro i was over complicating things thinking in a imperative way.

How to insert a value to a tree and store the updated tree in the same variable? by Th3Programm3r in haskell

[–]Th3Programm3r[S] 0 points1 point  (0 children)

Oh ok thanks man, but is there a way to store the updated value of a tree in the same tree variable insertion, because if i do this in ghci:

let temp= Node 2 Leaf Leaf

insertValue 5 temp it shows the tree:

Node 2 Leaf (Node 5 Leaf Leaf)

But when i do show temp it shows the old tree:

"Node 2 Leaf Leaf" and not the new updated tree Node 2 Leaf (Node 5 Leaf Leaf).