Last active
September 25, 2024 09:03
-
-
Save tonymorris/6109849 to your computer and use it in GitHub Desktop.
How to generalise this function?
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
-- 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
Something like this?