I am a beginner in Haskell, and I have been told that I should avoid using head and tail for list operation and use pattern matching instead. I got a code snippet here, and I wonder how should this be converted so that no head or tail is used?
myzipWith :: (a->b->c) -> [a] -> [b] ->[c]
myzipWith func [] [] = []
myzipWith func listA listB =
[func (head listA) (head listB) ] ++ (myzipWith func (tail listA) (tail listB))
myzipWith func (x:xs) (y:ys) = func x y : myzipWith func xs ys
. – Alexis Kinghead
andtail
. Let me ask, out of curiosity: were you given them? – jub0bshead
andtail
are defined should help:head (x:_) = x
andtail (_:xs) = xs
. – chepner