How to generalise this function?
| -- zip is to liftA2 as zipAlign is to ??? | |
| data NonEmptyList a = | |
| NonEmptyList a [a] | |
| deriving (Eq, Show) | |
| data ZipAlign a b = | |
| Align [(a, b)] | |
| | RestA (NonEmptyList a) | |
| | RestB (NonEmptyList b) | |
| deriving (Eq, Show) | |
| -- how to generalise this function... | |
| zipAlign :: | |
| [a] | |
| -> [b] | |
| -> ZipAlign a b | |
| zipAlign [] [] = | |
| Align [] | |
| zipAlign (h:t) [] = | |
| RestA (NonEmptyList h t) | |
| zipAlign [] (h:t) = | |
| RestB (NonEmptyList h t) | |
| zipAlign (h:t) (h':t') = | |
| case zipAlign t t' of | |
| RestA r -> RestA r | |
| RestB r -> RestB r | |
| Align a -> Align ((h,h') : a) | |
| data Ap f a = | |
| Ap a (f a) | |
| deriving (Eq, Show) | |
| data ZipAlignG f a b = | |
| AlignG (f (a, b)) | |
| | RestAG (Ap f a) | |
| | RestBG (Ap f b) | |
| -- ...to this function? | |
| zipAlignG :: | |
| f a | |
| -> f b | |
| -> ZipAlignG f a b | |
| zipAlignG = | |
| error "???" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Something like this?