Skip to content
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

merge should be a setter #3

Open
pranaysashank opened this issue Jul 1, 2018 · 0 comments
Open

merge should be a setter #3

pranaysashank opened this issue Jul 1, 2018 · 0 comments

Comments

@pranaysashank
Copy link
Contributor

merge is trivially a Setter. The current signature of merge

merge :: (IsMergeable a b c) => a -> b -> c can be changed to

merge :: (IsMergeable a b c) => Setter a c a b.

If this seems too much of a change, we can export a new setter mergeS that is defined in terms of the existing merge function as

-- This is a Setter with an additional IsMergeable constraint
mergeS :: (IsMergeable a b c, Settable f) => (a -> f b) -> a -> f c
mergeS  = sets (\f s -> merge (f s) s)

Additionally, the order in which we merge shouldn't matter. So changing the class definition slightly as

class (IsMergeable b a c) => (IsMergeable a b c) | a b -> c where
    merge :: a -> b -> c
    merge a b = merge b a -- flip merge

Example:

tn   :: TagNew String Validated
tnd :: TagNewDelta Validated
t     :: Tag String Validated

tn & mergeS .~ tnd == tnd & mergeS .~ tn  == t -- Tag String Validated

These should be simple fixes and can be incorporated into the library pretty easily.

Possible Future Improvements:
This also seems to indicate that the HasSplice class and IsMergeable class can be mixed into one. In a future improvement it can probably be developed in such a way as to say HasSplice c a b means c can be decomposed into a and b, and a and b can be merged to form a c, but this seems too much like sub typing in Java .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant