-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eq & Ord instance for Cursor. #117
Comments
I looked better into the code and yes, we cannot just remove these functions from It can benefit from some cleanup but I am generally ready to submit a pull request. However, if there are programs in the wild that make use of the inner workings of |
Adding derived instances of Eq & Ord requires modifying the inner workings of Cursor record (from the module Text.XML.Cursor.Generic), specifically: Siblings in Cursor were represented as functions (type synonym DiffCursor) that repeatedly append to a (presumably, empty) list until the desired list of nodes is generated. Such a function would later be invoked in various public top-level definitions in the module, but upon an empty list value exclusively. We rename Cursor to RecursiveCursor and add an eval function that evaluates a RecursiveCursor to a simpler data structure that takes the place of Cursor in the module interface. Then, we simplify the aforementioned public functions, replacing the invocations of DiffCursor upon an empty list by plain (nullary) values stored in our new, simpler Cursor data structure. Thus, we obtain a simpler data structure while preserving the interface. As the new Cursor data structure is free of functions, an Eq & Ord instance is now readily derivable.
Due to the knot tying, |
I observe there are functions in the record for
Cursor
(precedingSibling'
&followingSibling'
) that prevent me from deriving anEq
orOrd
instance and thus, for example, from usingCursor
with an ordinarySet
, or applying many ordinary list processing functions such asnub
. I notice, further, that the only way to construct aCursor
, a functiontoCursor'
found inText.XML.Cursor.Generic
, can accept various functions to put inprecedingSibling'
&followingSibling'
, but its only invocation fromtoCursor
specializes both of them toid
.In the light of these observations, could it be possible to simplify the definition of
Cursor
so as to make a derivedEq
instance possible? Or, if not, could you suggest some other way of defining a customEq
instance that makes sure any further operations on the equal cursors will have equal results? It would be nice if anOrd
instance gets to be possible as well.So far, I had to to
toMarkup
my cursors and only then compare. This is somewhat uncomfortable. Upon receiving directions, I could attempt to my ability at composing a pull request.The text was updated successfully, but these errors were encountered: