-
Notifications
You must be signed in to change notification settings - Fork 40
Make List.zipWith as lazy as expected #492
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
base: master
Are you sure you want to change the base?
Conversation
972fb7d to
08a229a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think zipWithK is very close to a dual-fold/bi-fold/zip-fold (not sure if there is a standard name), if we fuse the f and cons functions into one of type a -> b -> r -> r. Maybe it would make for a more general/intuitive function?
| where | ||
| go :: [a] %1 -> [b] %1 -> r | ||
| go [] [] = nil | ||
| go (a : as) [] = lefta a as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not entierely clear why the left{a,b} functions are taking head and tail as separate arguments. I guess the motivation is to make a NonEmpty list in zipWith' without having to call NonEmpty.fromList?
| (\a as -> ([], Just (Left (a :| as)))) | ||
| (\b bs -> ([], Just (Right (b :| bs)))) | ||
|
|
||
| zipWithk :: forall r a b c. (a %1 -> b %1 -> c) -> (c %1 -> r %1 -> r) -> r -> (a %1 -> [a] %1 -> r) -> (b %1 -> [b] %1 -> r) -> [a] %1 -> [b] %1 -> r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| zipWithk :: forall r a b c. (a %1 -> b %1 -> c) -> (c %1 -> r %1 -> r) -> r -> (a %1 -> [a] %1 -> r) -> (b %1 -> [b] %1 -> r) -> [a] %1 -> [b] %1 -> r | |
| zipWithK :: forall r a b c. (a %1 -> b %1 -> c) -> (c %1 -> r %1 -> r) -> r -> (a %1 -> [a] %1 -> r) -> (b %1 -> [b] %1 -> r) -> [a] %1 -> [b] %1 -> r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be better to split the argument types on several lines and document them, if this function is exported? Which I think it should be.
| Prelude.return () | ||
| where | ||
| xs :: [Word] | ||
| xs = List.zipWith (Num.+) (0 : error "bottom") [0 .. 42] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the motivation for using static bounds for ranges instead of property-supplied ones?
(same below)
| go [] (b : bs) = leftb b bs | ||
| go (a : as) (b : bs) = cons (f a b) (go as bs) | ||
|
|
||
| zipWith3 :: forall a b c d. (Consumable a, Consumable b, Consumable c) => (a %1 -> b %1 -> c %1 -> d) -> [a] %1 -> [b] %1 -> [c] %1 -> [d] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does zipWith3 doesn't get the same treatment with a zipWithK3?
| zipWithk f (:) [] consume2 consume2 | ||
| where | ||
| consume2 :: forall x y z. (Consumable x, Consumable y) => x %1 -> y %1 -> [z] | ||
| consume2 x y = x `lseq` y `lseq` [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In zipWith3 you do (x, y) `lseq` [] instead, any reason to prefer one or the other?
Fixes #491