First Project: Imperative Algorithm Visualization tool

I'm kindoff a beginner in haskell, I've mostly just been exploring the language, some of the introductory books on the subject and writing some small programs. This is one of my first projects I wanted to try out, but I'm feeling a bit lost on how to go about doing it. I want to build a tool which takes in inputs describing algorithms, probably in their imperative form and generate animations using SVG and HTML5 preferably or OpenGL. I find that being able to visualize the execution of an algorithm helped me understand the material a few years ago when i started college but I mostly had to do these on pen and paper. So my higher level idea on approaching this problem is: 1. Create a dsl for describing data structures, e.g Link lists, trees, graphs 2. Create a dsl for describing each step of the algorithms manipulating the data structures 3. The algorithms would be a monadic composition of the step ADTs 4. Lift the algorithm to some monad which carries out the side effects of making changes to a visualization. I'm sorry if I didn't use all the correct terminology for describing the problem, I'm not completely sure if it's an appropriate approach. My logic was that Since each state of the visualization is a sideeffect of executing an algorithm, it would be a seperate monad like IO, the entire algorithm can be represented as some form of a graph, I should have data types representing each component of the graph. I have no idea how to go about designing a DSL or for designing a monad which will handle the animations. Could someone help me approach the solution and what topics I want to look at to understand how to build the solution. Feel free to let me know if you'd like to help work on the tool, or if you think I should simplify my project in some way. This is mostly just an idea for a project and since I'm feeling pretty beginnerish with the language, i wouldnt love suggestions on a simpler project which can sorta lead me in a direction in which i can make this tool in the future. Thank You! -- Adit Biswas

On Mon, Nov 10, 2014 at 12:49 AM, Adit Biswas
I have no idea how to go about designing a DSL or for designing a monad which will handle the animations.
Is it really about DSLs and monads? Or is it first getting a grasp of the problem space? You're trying to chew everything at once in a first bite. Scope out the smallest meaningful chunk and use that experiential learning to direct where to go next. "If you can't solve a problem, then there is an easier problem you can solve: find it." -- Polya -- Kim-Ee

Hi Adit, On Sun, Nov 09, 2014 at 11:19:48PM +0530, Adit Biswas wrote:
So my higher level idea on approaching this problem is: 1. Create a dsl for describing data structures, e.g Link lists, trees, graphs 2. Create a dsl for describing each step of the algorithms manipulating the data structures 3. The algorithms would be a monadic composition of the step ADTs 4. Lift the algorithm to some monad which carries out the side effects of making changes to a visualization.
I would start with defining the data structures which represent your algorithm and then defining a function that renders your data. If you're using OpenGL ist could be as simple as: render :: YourData -> IO () If you've a working version of this, then you could try defining a DSL, and if you want a monadic one, then most likely you will be using a free monad[1,2], so you don't have to write your own one. But at the end runnning your DSL will just result into 'YourData' and you can reuse your 'render' function. You don't need any kind of special Monad for the rendering and I also don't see any kind of advantage having one. Greetings, Daniel [1] http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.htm... [2] https://hackage.haskell.org/package/free

Hi Adit,
animations in OpenGL are mostly not exactly trivial - there's several
routes you can take, from simple to not simple at all (buffers,
shaders ...). But maybe you know the problem space already.
Some example sources for animations in Haskell:
- OpenGL, simple animation with rotations and translations:
https://github.com/haskell-opengl/GLUT/blob/master/examples/Misc/Gears.hs
- SDL2, using sprites:
https://github.com/haskell-game/sdl2/blob/new-api/examples/lazyfoo/Lesson11....
As the others said, it's probably better to start with a small
problem, build up to what you want to build, and see if you can
abstract from there ...
Cheers,
Elise
On 10 November 2014 10:26, Daniel Trstenjak
Hi Adit,
On Sun, Nov 09, 2014 at 11:19:48PM +0530, Adit Biswas wrote:
So my higher level idea on approaching this problem is: 1. Create a dsl for describing data structures, e.g Link lists, trees, graphs 2. Create a dsl for describing each step of the algorithms manipulating the data structures 3. The algorithms would be a monadic composition of the step ADTs 4. Lift the algorithm to some monad which carries out the side effects of making changes to a visualization.
I would start with defining the data structures which represent your algorithm and then defining a function that renders your data.
If you're using OpenGL ist could be as simple as:
render :: YourData -> IO ()
If you've a working version of this, then you could try defining a DSL, and if you want a monadic one, then most likely you will be using a free monad[1,2], so you don't have to write your own one.
But at the end runnning your DSL will just result into 'YourData' and you can reuse your 'render' function.
You don't need any kind of special Monad for the rendering and I also don't see any kind of advantage having one.
Greetings, Daniel
[1] http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.htm... [2] https://hackage.haskell.org/package/free _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (4)
-
Adit Biswas
-
Daniel Trstenjak
-
Elise Huard
-
Kim-Ee Yeoh