On Tue, Mar 22, 2011 at 2:20 PM, Edward Kmett <[email protected]> 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 <[email protected]> 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 <[email protected]>
>>>
>>> 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
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to