Skip to main content
add advice about not using recursion
Source Link
Anonymous
  • 2.2k
  • 10
  • 14

The end-of-list patterns can be combined into one:

zip4 (b:bs) (c:cs) (d:ds) (e:es) = (b,c,d,e) : zip4' bs cs ds es
zip4 _ _ _ _ = []

There's no need for a separate zip4' helper.

This definition is correct, but it's unnecessarily complex. List functions like this are usually defined in terms of more general list functions like map, rather than by explicit recursion. The actual definition of zip4 is:

zip4 =  zipWith4 (,,,)

Doing recursion exercises like reimplementing standard list functions can teach you the bad habit of using recursion even when you don't need it. Good Haskell code does almost all list manipulation with high-order functions or list comprehensions. It's better practice to use them than reimplement them.

The end-of-list patterns can be combined into one:

zip4 (b:bs) (c:cs) (d:ds) (e:es) = (b,c,d,e) : zip4' bs cs ds es
zip4 _ _ _ _ = []

There's no need for a separate zip4' helper.

This definition is correct, but it's unnecessarily complex. List functions like this are usually defined in terms of more general list functions like map, rather than by explicit recursion. The actual definition of zip4 is:

zip4 =  zipWith4 (,,,)

The end-of-list patterns can be combined into one:

zip4 (b:bs) (c:cs) (d:ds) (e:es) = (b,c,d,e) : zip4' bs cs ds es
zip4 _ _ _ _ = []

There's no need for a separate zip4' helper.

This definition is correct, but it's unnecessarily complex. List functions like this are usually defined in terms of more general list functions like map, rather than by explicit recursion. The actual definition of zip4 is:

zip4 = zipWith4 (,,,)

Doing recursion exercises like reimplementing standard list functions can teach you the bad habit of using recursion even when you don't need it. Good Haskell code does almost all list manipulation with high-order functions or list comprehensions. It's better practice to use them than reimplement them.

Source Link
Anonymous
  • 2.2k
  • 10
  • 14

The end-of-list patterns can be combined into one:

zip4 (b:bs) (c:cs) (d:ds) (e:es) = (b,c,d,e) : zip4' bs cs ds es
zip4 _ _ _ _ = []

There's no need for a separate zip4' helper.

This definition is correct, but it's unnecessarily complex. List functions like this are usually defined in terms of more general list functions like map, rather than by explicit recursion. The actual definition of zip4 is:

zip4 =  zipWith4 (,,,)