Created
June 20, 2017 12:47
-
-
Save sjoerdvisscher/c84d6ae6ff6fdb80df9b772f5fdb421b to your computer and use it in GitHub Desktop.
Generic unification with one-liner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- See https://www.reddit.com/r/haskell/comments/6htj7z/generic_unification/ | |
default zipMatch :: (ADT1 t, Constraints01 t Eq Unifiable) => t a -> t a -> Maybe (t (Either a (a, a))) | |
zipMatch = runZip $ generic01 @Eq @Unifiable | |
(Zip $ \a b -> if a == b then Just a else Nothing) | |
(\(Zip f) -> Zip $ \a b -> zipMatch a b >>= traverse (either (\x -> f x x) (uncurry f))) | |
(Zip $ \a b -> Just $ Right (a, b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment