Skip to content

Conversation

@aspiwack
Copy link
Member

Fixes #491

Copy link
Member

@tbagrel1 tbagrel1 left a 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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Member

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]
Copy link
Member

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]
Copy link
Member

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` []
Copy link
Member

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?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zipWith throws NonTermination exception

3 participants