Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3850050
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:56:58+00:00 2026-05-19T16:56:58+00:00

For learning purposes I am trying to write my own implementation of the zipWith

  • 0

For learning purposes I am trying to write my own implementation of the zipWith function. However, I am hitting an issue with pattern matching on edge cases with _. First I will describe the good case, then the bad case. Hopefully someone will be able to explain why they behave differently. Thanks

If I write the zipWith function as follows, it works (Note the order of the edge cases matching empty list on lines 2 & 3):-

zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
zipwith' _ [] _ = []
zipWith' _ _ [] = []
zipWith' f (x:xs) (y:ys) = f x y : zipWith' f xs ys

Compiling in GHCI:-

ghci> :l ZipWith.hs 
[1 of 1] Compiling Main             ( ZipWith.hs, interpreted )

Ok, the above is fine, yet if I swap the pattern matching for the edge cases around GHCI throws ‘Multiple declarations of’ error for lines 2 and 4.

zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith' _ _ [] = []
zipwith' _ [] _ = []
zipWith' f (x:xs) (y:ys) = f x y : zipWith' f xs ys

Compiling in GHCI:-

ZipWith.hs:4:0:
    Multiple declarations of `Main.zipWith''
    Declared at: ZipWith.hs:2:0
                 ZipWith.hs:4:0
Failed, modules loaded: none.

I’m stumped…

  1. Looking at the patterns on lines 2 and 4 they seem mutually exclusive but i’m obviously missing something fundamental here
  2. Why would switching the patterns on lines 2 and 3 cause the compilation error to go away.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:56:59+00:00Added an answer on May 19, 2026 at 4:56 pm

    The error message isn’t complaining about overlapping patterns (your patterns do overlap in the case of two empty lists, but that’s neither the problem, nor a problem), but multiple definitions of the zipWith function.

    The reason for that is that in your second case you have one definition of zipWith followed by an unrelated definition of zipwith (note the lower case w), followed by a new, conflicting definition of zipWith. In other words it’s a simple typo. (Did take me a while to see though – quite a sneaky typo)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write something very similar to an IM client (for learning purposes
I'm trying to write a very simple cms (for learning purposes) in kohana 3
For learning purposes, I'm trying to make a function using Python that takes in
I'm currently trying to write a website for testing / learning purposes that will
I'm trying to develop a personal MVC framework for learning purposes. But every time
I'm trying to setup a new web-application for learning purposes using the newest technologies:
I am trying to modify a simply chat application for learning purposes. The only
I am trying to write a Spider Solitaire player as an exercise in learning
I'm new to Objective-c. For learning purposes I'm trying to build something like a
I'm trying to build a safari extenstion (mostly for learning purposes) that creates a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.