Alexander Berntsen | 12 Nov 00:42 2013
Picon

Looking for feedback on my Haskell game programming paper


Someone suggested I posted this here:
<https://secure.plaimi.net/~alexander/tmp/main.pdf>.

"This" being an informal introduction to game programming in Haskell,
aimed at game programmers used to C or C-likes.

I and a fellow student originally wrote it for a class, but someone
(someone else than the first someone) found the URL and posted it on
Reddit[0], and various other people have read it as well -- so we
already have some feedback to go on. But we welcome more feedback.

It has yet to be shared outside of the Haskell community, as I would
like to polish it first, and reach a 1.0 version. (Hopefully this week!)

The game presented in the paper is far from finished. We aim towards a
full-blown but small game. It should have multi-player, AI,
networking, somewhat complicated physics, control handling, menus, a
graphics system, and so on and so forth. Basically it should cover
"everything", but still be small enough to serve as an example.

Contributions to the game itself would be also be greatly appreciated.
Its source is available on GitHub[1].

[0]
<http://www.reddit.com/r/haskell/comments/1q1b9f/plaimis_introduction_to_haskell_for_the/>
[1]
<http://www.reddit.com/r/haskell/comments/1q1b9f/plaimis_introduction_to_haskell_for_the/>
--

-- 
Alexander
(Continue reading)

C K Kashyap | 22 Mar 17:29 2011
Picon

Looking for feedback on my attempt at a tree construction edsl

Hi,

With my "edsl", one can describe a tree like this -

import TreeEdsl
import Data.Tree

createTree :: TreeContext String ()
createTree = do
insertSubTree "Fruits" $ do
insertLeaf "Apple"
insertLeaf "Mango"
insertSubTree "Arbitrary" $ do
insertSubTree "Numbers" $ do
insertLeaf "1"
insertLeaf "2"
insertLeaf "3"
insertSubTree "Letters" $ do
insertLeaf "A"
insertLeaf "B"
insertLeaf "C"
return ()
main = do
tree <- process "root" createTree
putStrLn (drawTree (fmap show tree))
return ()


and get a tree like this - 

"root"
|
+- "Arbitrary"
|  |
|  +- "Letters"
|  |  |
|  |  +- "C"
|  |  |
|  |  +- "B"
|  |  |
|  |  `- "A"
|  |
|  `- "Numbers"
|     |
|     +- "3"
|     |
|     +- "2"
|     |
|     `- "1"
|
`- "Fruits"
   |
   +- "Mango"
   |
   `- "Apple"

 

I'd appreciate your feedback on this. Does this qualify to be a edsl?

Regards,
Kashyap
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Yves Parès | 22 Mar 18:15 2011
Picon

Re: Looking for feedback on my attempt at a tree construction edsl

You could turn 'insertSubTree' into and operator, and shorten "insertLeaf"

createTree = do
    "Fruits" +> do
                leaf "Apple"
                leaf "Mango
    "Arbitrary" +> do
                   leaf "1"
    -- and so on...

It's a little bit more concise.
But I fail to see the use of TreeContext being an instance of Monad.

2011/3/22 C K Kashyap <ckkashyap <at> gmail.com>
Hi,
With my "edsl", one can describe a tree like this -

import TreeEdsl
import Data.Tree

createTree :: TreeContext String ()
createTree = do
insertSubTree "Fruits" $ do
insertLeaf "Apple"
insertLeaf "Mango"
insertSubTree "Arbitrary" $ do
insertSubTree "Numbers" $ do
insertLeaf "1"
insertLeaf "2"
insertLeaf "3"
insertSubTree "Letters" $ do
insertLeaf "A"
insertLeaf "B"
insertLeaf "C"
return ()
main = do
tree <- process "root" createTree
putStrLn (drawTree (fmap show tree))
return ()


and get a tree like this - 

"root"
|
+- "Arbitrary"
|  |
|  +- "Letters"
|  |  |
|  |  +- "C"
|  |  |
|  |  +- "B"
|  |  |
|  |  `- "A"
|  |
|  `- "Numbers"
|     |
|     +- "3"
|     |
|     +- "2"
|     |
|     `- "1"
|
`- "Fruits"
   |
   +- "Mango"
   |
   `- "Apple"

 

I'd appreciate your feedback on this. Does this qualify to be a edsl?

Regards,
Kashyap

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Edward Kmett | 22 Mar 20:20 2011
Picon

Re: Looking for feedback on my attempt at a tree construction edsl

If you add an instance of IsString to handle leaf construction you can get it down to


    "Fruits" +> do
       "Apple"
       "Mango"
    "Arbitrary" +> do
       "1"
       "..."

But I also don't see the point of doing this in a monad.

-Edward

On Tue, Mar 22, 2011 at 1:15 PM, Yves Parès <limestrael <at> gmail.com> wrote:
You could turn 'insertSubTree' into and operator, and shorten "insertLeaf"

createTree = do
    "Fruits" +> do
                leaf "Apple"
                leaf "Mango
    "Arbitrary" +> do
                   leaf "1"
    -- and so on...

It's a little bit more concise.
But I fail to see the use of TreeContext being an instance of Monad.

2011/3/22 C K Kashyap <ckkashyap <at> gmail.com>
Hi,
With my "edsl", one can describe a tree like this -

import TreeEdsl
import Data.Tree

createTree :: TreeContext String ()
createTree = do
insertSubTree "Fruits" $ do
insertLeaf "Apple"
insertLeaf "Mango"
insertSubTree "Arbitrary" $ do
insertSubTree "Numbers" $ do
insertLeaf "1"
insertLeaf "2"
insertLeaf "3"
insertSubTree "Letters" $ do
insertLeaf "A"
insertLeaf "B"
insertLeaf "C"
return ()
main = do
tree <- process "root" createTree
putStrLn (drawTree (fmap show tree))
return ()


and get a tree like this - 

"root"
|
+- "Arbitrary"
|  |
|  +- "Letters"
|  |  |
|  |  +- "C"
|  |  |
|  |  +- "B"
|  |  |
|  |  `- "A"
|  |
|  `- "Numbers"
|     |
|     +- "3"
|     |
|     +- "2"
|     |
|     `- "1"
|
`- "Fruits"
   |
   +- "Mango"
   |
   `- "Apple"

 

I'd appreciate your feedback on this. Does this qualify to be a edsl?

Regards,
Kashyap

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Stephen Tetley | 22 Mar 20:45 2011
Picon

Re: Looking for feedback on my attempt at a tree construction edsl

Andy Gill uses a monad in his Dot library to allow graphs to have
references as they are built. It's a pattern I like a lot and has been
very useful for my graphics kit Wumpus.

That said, while it's a good technique for graphs, its use is more
equivocal for trees where nesting is more prominent. I use a reference
monad for tree building/drawing at the moment (references are
essential) but I'd switch to a technique that is better with nesting
if I could think of one.

At the moment the Tree EDSL doesn't use references, so I'd "third" the
notion that the code would be simpler if it was pure.
Antoine Latter | 22 Mar 21:57 2011
Picon

Re: Looking for feedback on my attempt at a tree construction edsl

On Tue, Mar 22, 2011 at 2:20 PM, Edward Kmett <ekmett <at> gmail.com> wrote:
> If you add an instance of IsString to handle leaf construction you can get
> it down to
>     "Fruits" +> do
>        "Apple"
>        "Mango"
>     "Arbitrary" +> do
>        "1"
>        "..."
> But I also don't see the point of doing this in a monad.

Having it in a monad has the same benefit as blaze-html being built in
a monad: the square braces and comas for the list are gone. Although
it does leave you with an awkward type parameter hanging around.

And the same as the Binary Put monad vs. the Binary Builder type.

I prefer the monoid interface vs. the monad interface to both of
these, but I can see the appeal.

Antoine

> -Edward
>
> On Tue, Mar 22, 2011 at 1:15 PM, Yves Parès <limestrael <at> gmail.com> wrote:
>>
>> You could turn 'insertSubTree' into and operator, and shorten "insertLeaf"
>>
>> createTree = do
>>     "Fruits" +> do
>>                 leaf "Apple"
>>                 leaf "Mango
>>     "Arbitrary" +> do
>>                    leaf "1"
>>     -- and so on...
>>
>> It's a little bit more concise.
>> But I fail to see the use of TreeContext being an instance of Monad.
>>
>> 2011/3/22 C K Kashyap <ckkashyap <at> gmail.com>
>>>
>>> Hi,
>>> With my "edsl", one can describe a tree like this -
>>> import TreeEdsl
>>> import Data.Tree
>>> createTree :: TreeContext String ()
>>> createTree = do
>>> insertSubTree "Fruits" $ do
>>> insertLeaf "Apple"
>>> insertLeaf "Mango"
>>> insertSubTree "Arbitrary" $ do
>>> insertSubTree "Numbers" $ do
>>> insertLeaf "1"
>>> insertLeaf "2"
>>> insertLeaf "3"
>>> insertSubTree "Letters" $ do
>>> insertLeaf "A"
>>> insertLeaf "B"
>>> insertLeaf "C"
>>> return ()
>>> main = do
>>> tree <- process "root" createTree
>>> putStrLn (drawTree (fmap show tree))
>>> return ()
>>>
>>> and get a tree like this -
>>> "root"
>>> |
>>> +- "Arbitrary"
>>> |  |
>>> |  +- "Letters"
>>> |  |  |
>>> |  |  +- "C"
>>> |  |  |
>>> |  |  +- "B"
>>> |  |  |
>>> |  |  `- "A"
>>> |  |
>>> |  `- "Numbers"
>>> |     |
>>> |     +- "3"
>>> |     |
>>> |     +- "2"
>>> |     |
>>> |     `- "1"
>>> |
>>> `- "Fruits"
>>>    |
>>>    +- "Mango"
>>>    |
>>>    `- "Apple"
>>>
>>> My code is here
>>>
>>> https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/edsl/TreeEdsl.hs
>>> I'd appreciate your feedback on this. Does this qualify to be a edsl?
>>> Regards,
>>> Kashyap
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe <at> haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe <at> haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
C K Kashyap | 23 Mar 06:45 2011
Picon

Re: Looking for feedback on my attempt at a tree construction edsl

Hi,

I've tried a non-monadic version based on the suggestions here - https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/edsl/TreeWithoutMonad.hs
This implementation seems to lack the "indentation based" approach that the do syntax allows.

Would I be right if I said that the non-monadic version is "shallow embedding" and the monadic approach is deep embedding? Can we do deep embedding without using monads?

Regards,
Kashyap
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Stephen Tetley | 23 Mar 09:18 2011
Picon

Re: Looking for feedback on my attempt at a tree construction edsl

A shallow embedding would typically use just functions - a famous
example is Paul Hudak's "region server". A deep embedding would build
syntax - represented with data types - and interpret the syntax or
compile the syntax for another use (so called "off-shoring" e.g. Conal
Elliott's Pan).
C K Kashyap | 23 Mar 11:28 2011
Picon

Re: Looking for feedback on my attempt at a tree construction edsl

A shallow embedding would typically use just functions - a famous
example is Paul Hudak's "region server". A deep embedding would build
syntax - represented with data types - and interpret the syntax or
compile the syntax for another use (so called "off-shoring" e.g. Conal
Elliott's Pan).


I am not able to ascertain  if what you are saying is consistent with  http://www.haskell.org/haskellwiki/Embedded_domain_specific_language 

Regards,
Kashyap
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Stephen Tetley | 23 Mar 12:47 2011
Picon

Re: Looking for feedback on my attempt at a tree construction edsl

On 23 March 2011 10:28, C K Kashyap <ckkashyap <at> gmail.com> wrote:

> I am not able to ascertain  if what you are saying is consistent with
>  http://www.haskell.org/haskellwiki/Embedded_domain_specific_language
> Regards,
> Kashyap

Well - I'm not sure if the description of a shallow embedding on that
page is particularly enlightening...

Gmane