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 7976149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:50:49+00:00 2026-06-04T08:50:49+00:00

Consider the following problem: given a list of length three of tuples (String,Int), is

  • 0

Consider the following problem: given a list of length three of tuples (String,Int), is there a pair of elements having the same “Int” part? (For example, [("bob",5),("gertrude",3),("al",5)] contains such a pair, but [("bob",5),("gertrude",3),("al",1)] does not.)

This is how I would implement such a function:

import Data.List (sortBy)
import Data.Function (on)

hasPair::[(String,Int)]->Bool
hasPair = napkin . sortBy (compare `on` snd)
  where napkin [(_, a),(_, b),(_, c)] | a == b = True
                                      | b == c = True
                                      | otherwise = False

I’ve used pattern matching to bind names to the “Int” part of the tuples, but I want to sort first (in order to group like members), so I’ve put the pattern-matching function inside a where clause. But this brings me to my question: what’s a good strategy for picking names for functions that live inside where clauses? I want to be able to think of such names quickly. For this example, “hasPair” seems like a good choice, but it’s already taken! I find that pattern comes up a lot – the natural-seeming name for a helper function is already taken by the outer function that calls it. So I have, at times, called such helper functions things like “op”, “foo”, and even “helper” – here I have chosen “napkin” to emphasize its use-it-once, throw-it-away nature.

So, dear Stackoverflow readers, what would you have called “napkin”? And more importantly, how do you approach this issue in general?

  • 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-04T08:50:50+00:00Added an answer on June 4, 2026 at 8:50 am

    General rules for locally-scoped variable naming.

    • f , k, g, h for super simple local, semi-anonymous things
    • go for (tail) recursive helpers (precedent)
    • n , m, i, j for length and size and other numeric values
    • v for results of map lookups and other dictionary types
    • s and t for strings.
    • a:as and x:xs and y:ys for lists.
    • (a,b,c,_) for tuple fields.

    These generally only apply for arguments to HOFs. For your case, I’d go with something like k or eq3.

    Use apostrophes sparingly, for derived values.

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

Sidebar

Related Questions

Consider the following problem. We are given an array of elements belonging to one
Consider the following problem: A multi-line string $junk contains some lines which are encoded
Propose to consider the following problem. Suppose we have some composite object. Are there
The Problem Consider the following vectors: std::vector<std::string> extensions; extensions.push_back(.cpp); extensions.push_back(.CPP); extensions.push_back(.h); extensions.push_back(.H); std::vector<std::string> caselessUniqueExtensions;
I've been given the following problem about loop invariants: Consider x=4; for(i=5;i<k;i++) { a=a+x+i;
Consider the following problem: There are N coins numbered 1 to N. You can't
Consider following code: My problem is: 1) I can't seem to cast the errors
This problem is only in IE. Consider the following HTML: <html> <body> <div style='position:absolute;left:1em;right:1em;top:1em;bottom:1em;overflow:auto;>
Consider following string Some string with quotes and \pre-slashed\ quotes Using regex, I want
Consider following 2 programs giving same error First calss: public class Testing { Testing

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.