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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:34:50+00:00 2026-06-01T12:34:50+00:00

There is some type Record : type Day = Integer type Description = String

  • 0

There is some type Record:

type Day         = Integer
type Description = String
type Name        = String
type PhoneNumber = String
type Year        = Integer

data Month = January | February | March | April | May | June | July
           | August | September | October | November | December
           deriving (Eq, Ord, Enum, Show)
data Birthday = Birthday Month Day
  deriving (Eq, Show)
data DatingDate = DatingDate Year Month Day
  deriving (Eq, Show)

data Record = BirthdayRecord Name Birthday
            | PhoneRecord Name PhoneNumber
            | DatingRecord DatingDate Description
            deriving (Eq, Show)

And function, which filter these record by date:

getAssignment :: (Year, Month, Day) -> [Record] -> [Record]
getAssignment (year, month, day) = filter matchDate
  where matchDate (BirthdayRecord _ (Birthday month day)) = True
        matchDate (DatingRecord (DatingDate year month day) _) = True
        matchDate _ = False

This definition of getAssignment is not correct because of error:

warning: Defined but not used: `year'

Actually, it is kind of surprise for me, that year in pattern matched part of getAssignment and year in pattern matched part of matchDate are not the same.

So, where is the scope bounds of year variable started and finished? It happens because of where section?

Btw, this error can be avoided with some redundant numerous using of (year, month, day) variables.

getAssignment' :: (Year, Month, Day) -> [Record] -> [Record]
getAssignment' date = filter (matchDate date)
  where matchDate (_, m, d) (BirthdayRecord _ (Birthday month day)) =
          month == m && day == d
        matchDate (y, m, d) (DatingRecord (DatingDate year month day) _) =
          year == y && month == m && day == d
        matchDate _ _ = False

How can it be rewritten?

  • 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-01T12:34:52+00:00Added an answer on June 1, 2026 at 12:34 pm

    The scope is the whole expression (including the definitions in the where-clause), EXCEPT that variables in a pattern always define a new variable binding.

    Instead of reusing the same names, you should use different variable names in the inner bindings.

    getAssignment :: (Year, Month, Day) -> [Record] -> [Record]
    getAssignment (year, month, day) = filter matchDate
      where matchDate (BirthdayRecord _ (Birthday month' day'))
               = month == month' && day == day'
            matchDate (DatingRecord (DatingDate year' month' day') _)
               = year == year' && month == month' && day == day'
            matchDate _ = False
    

    Reusing a variable name so that it hides a variable from an outer scope is called shadowing. GHC should warn you when you do this if you use -Wall (or -fwarn-name-shadowing to enable only this warning).

    Edit: For your particular function, this is probably a clearer way to write it:

    getAssignment :: (Year, Month, Day) -> [Record] -> [Record]
    getAssignment (year, month, day) = filter matchDate
      where matchDate (BirthdayRecord _ birthday) = birthday == Birthday month day
            matchDate (DatingRecord date _)       = date == DatingDate year month day
            matchDate _                           = False
    

    But you can’t avoid giving a name to part of the pattern if you want to use it, even if only to compare it to something else.

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

Sidebar

Related Questions

Given a text string containing a type name, is there some way to get
I have a Type, a String and an Object. Is there some way I
Is there some type of cap as to how much CPU an applet can
Does anyone know if there is some type of tool, preferably a Firefox add
Is there a way to get a file's MIME type using some system call
These are probably are pretty simple YES|NO type questions. I have some NSDictionaries containing
Is there some way when sending this message to specify that I rather have
Is there some way to compile (with the CSC task) a WPF Application with
Is there some kind of a shorthand fluent interface for creating a parameters dictionary
I have a big fat query that's written dynamically to integrate some data. Basically

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.