
Aha. I see the point. The current design was influenced from some
other implementation that I spot somewhere in the net. I will change
it but this reminds me of another problem. Most movement functions
raise error if they can't do the movement. This is convenient if you
somehow know that the direction in which you go always exists.
Alternatively I can use monad with failure. In other words, there are
two possibilities:
1. Use error ".." and types like: TreeLoc a -> TreeLoc a
2. Use monad and type like: Monad m => TreeLoc a -> m (TreeLoc a)
In the second case some one have to do something like this to check
whether the operation is successful:
case left loc of
Noting -> error "something gone wrong"
Just loc -> ...
In the first case there is no way to check for success but someone can
use precondition:
if isFirst loc
then do_something (left loc)
else i_cannot_go_left
In my opinion 1 looks nicer but 2 also have advantages. What do you think?
Regards,
Krasimir
On Fri, May 23, 2008 at 12:33 AM, Conal Elliott
* Every definition of tp
I meant "of type", forgetting that my emacs abbrevs don't expand in gmail.
On Thu, May 22, 2008 at 2:13 PM, Conal Elliott
wrote: Hi Krasimir,
I had a long exchange with chessguy about this interface, suggesting a significant change in style, simplifying the type. (Incidentally, the change removed the State and hence mtl dependence.)
The conversation is on http://tunes.org/~nef/logs/haskell/08.05.17, starting with "12:08:11 <chessguy> w00t!" and really picking up with "<conal> chessguy: something smells funny ...".
Here's a summary of the conversation, though I encourage you to read the whole thing:
* Every definition of tp 'State (TreeLoc a) a', does a getLabel at the end (except getLabel). * Often users of those movement functions discard the result. * Simpler and more orthogonal would be remove the getLabel and return 'State (TreeLoc a) ()' instead. * Now remove that return value altogether, simplifying the type of zipper movements to just 'TreeLoc a -> TreeLoc a'. Then they compose nicely with (.), having id as identity. * Simplify the type of getLabel to just 'TreeLoc a -> a'. Now no more State.
Cheers, - Conal
On Thu, May 22, 2008 at 12:52 PM, Krasimir Angelov
wrote: Hello Guys,
We have Data.Tree in the standard libraries for a long time but for some reason we still don't have standard implementation for Zipper. I wrote recently one implementation for Yi but there are many other versions hanging around. At least I know for some. I propose to add one in the standard libraries i.e. the "containers" package. The version that I use currently is here:
http://code.haskell.org/yi/Data/Tree/Zipper.hs
If you would like to do code review I will be happy to hear comments. After the API is settled down I will write test cases also. One thing that is worying me is that the current version uses State monad which is in the "mtl" package while the natural place for Data.Tree.Zipper is in "containers". This will create an extra dependency. Is this acceptable?
Regards, Krasimir _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe