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

  • Home
  • SEARCH
  • 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 9132985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:24:26+00:00 2026-06-17T08:24:26+00:00

In defining multiple pattern matches for a function, for instance as follows: 1: takeTree

  • 0

In defining multiple pattern matches for a function, for instance as follows:

1: takeTree 0 tree                           = Leaf
2: takeTree levels (Leaf)                    = Leaf
3: takeTree levels (Branch value left right) = Branch value (takeTree...

I get two warnings in particular:

Source.hs:1: Warning: Defined but not used: `tree’

Source.hs:2: Warning: Defined but not used: `levels’

I’m not immediately convinced these are useful warnings though. If my code were instead:

1: takeTree 0 _                              = Leaf
2: takeTree _ (Leaf)                         = Leaf
3: takeTree levels (Branch value left right) = Branch value (takeTree...

which, fixes the warnings, I now find it to be far less readable, and obfuscates the semantics of what I expect as input values.

Why is Defined but not used a reasonable warning at all here, when among my exhaustive patterns each argument is in fact used at least once?

  • 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-06-17T08:24:27+00:00Added an answer on June 17, 2026 at 8:24 am

    I’ve made coding errors that were pointed out by this warning. Simplified example:

    fun x xs = go xs
      where
        go []      = ... 
        go (y:xs') = f y (go xs)
    

    The recursive call should have xs' as argument, of course, and the “defined but not used” warning will catch that. To me, that’s worth the inconvenience of using _ for unused matches.

    The compiler is not able to guess your intentions, and the fact that you used the argument in another match does not mean that you didn’t mean to use it in the match that generates the warning. After all, you could have used tree, so the warning that you didn’t is reasonable.

    See also the answer by Ben: you can use _name to use a name but still suppress the warning.

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

Sidebar

Related Questions

Does defining multiple variables on one line offer some form of optimization for the
I was curious about defining multiple lexically scoped functions in Scheme that can call
I am defining a StackPanel containing multiple Buttons in my xaml file. I'd like
I'm defining a TestList (HUnit) and want to spread the definition over multiple lines.
Im defining my cfc's and would like to know how you can define multiple
Lets say i use the shorhand background property defining multiple properties..eg: .img { background:
Suppose I have multiple roles, each one defining a set of items: package A;
i have multiple spiders in one project , problem is right now i am
What does the following javascript code mean? I guess it's defining a function within
is there any shorthand method of defining multiple objects of the same class in

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.