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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:48:00+00:00 2026-05-13T20:48:00+00:00

if i do any isUpper asBsd , i’ll get True . here, the second

  • 0

if i do any isUpper "asBsd", i’ll get True.
here, the second element to any is a string.
but, if i do this:

any ("1" `isInfixOf`) ["qas","123","=-0"]

the second element to any is a list of strings.
how and why this difference between those 2 functions?

another example.
if i write filter isUpper "asdVdf" , i’ll get "V".
here, the second element to filter, is a string.
but, if i write this:
filter (isUpper . head) ["abc","Vdh","12"] , i’ll get ["Vdh"].
as you can see, the second element to filter is now a list of strings.
why there is a differences and how haskell know’s it’s right in both cases?

to summarize it:
i don’t understand how in the same function, one time haskell get a second element that is a string, and in other time, haskell get a list of strings, in the second element.
one time it happened in any function, and the other time in filter function.
how haskell(and me) know’s it’s right in both cases?

thanks :-).

  • 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-13T20:48:00+00:00Added an answer on May 13, 2026 at 8:48 pm

    Because isUpper is a Char -> Bool function and "1" ‘isInfixOf‘ and isUpper . head are [Char] -> Bool functions


    "1" `isInfixOf` xxx
    

    can be rewritten as

    isInfixOf "1" xxx
    

    We knew the type of isInfixOf is [a] -> [a] -> Bool1. Now the first argument to isInfixOf is "1" which is of type [Char], so we can deduce a is a Char:

         isInfixOf :: [a]    -> [a] -> Bool
           "1"     :: [Char]
    //∴ a = Char and
     isInfixOf "1" ::           [a] -> Bool
                    =        [Char] -> Bool
    

    That means isInfixOf "1" is now a [Char] -> Bool function.

    Now, the type of any is (a -> Bool) -> [a] -> Bool function. As above,

                   any :: (a      -> Bool) -> [a] -> Bool
         isInfixOf "1" :: ([Char] -> Bool)
     //∴ a = [Char] and
    

    any (isInfixOf “1”) :: [a] -> Bool
    = [[Char]] -> Bool

    In order to satisfy with the type constraint of any (isInfixOf "1"), the argument must be a string list.


    Now consider isUpper. The type of isUpper is Char -> Bool. Hence:

                  any :: (a    -> Bool) -> [a] -> Bool
              isUpper :: (Char -> Bool)
    //∴ a = Char and
          any isUpper ::                   [a] -> Bool
                       =                [Char] -> Bool
    

    So any isUpper needs to take a string only, instead of a string list.


    Finally, isUpper . head. In Haskell, the types of the relevant functions are:

     filter :: (a -> Bool) -> [a] -> [a]
       head :: [a] -> a
    isUpper :: Char -> Bool
        (.) :: (b -> c) -> (a -> b) -> a -> c
    

    Hence for filter isUpper, a = Char and the type is [Char] -> [Char], i.e. it needs to take a string as parameter.

    And2:

                (.) :: (b    -> c   ) -> (a   -> b) -> a -> c
            isUpper :: (Char -> Bool)
               head ::                   ([b] -> b)
    //∴ c = Bool, b = Char, a = [b] = [Char], and
     isUpper . head ::                                 a -> c
                    =                             [Char] -> Bool
    

    Thus for filter (isUpper . head), we have a = [Char] and the type is [[Char]] -> [[Char]], i.e. it needs to take a string list as parameter.


    Note:

    1. The type of isInfixOf is actually (Eq a) => [a] -> [a] -> Bool as the equality must be valid for type a, but this is irrelevant in our analysis.
    2. I’ve temporarily changed the variable a to b for head, but it doesn’t matter.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have you checked the latest version of UC? The release… May 16, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer IQueryable's LINQ methods take Expression Trees, not normal delegates. Therefore,… May 16, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer You could consider using JSONPath, JSONQuery, jLinq, etc... although under-the-hood… May 16, 2026 at 11:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Any help most appreciated, this is driving me insane. I'm doing exactly what I
Any existing function that can handle this problem? Input: A B C output: {A},{B},
Any comments/improvements on this process? User Table: id, username, password, salt Storing a New
Any help with this problem would be fantastic. I appreciate all contributions! Let us
I have a string that is one of the following forms ABC // all
I want to find the first index of substrings in a larger string. I
:) This might look to be a very long question to you I understand,
Consider a JavaScript method that needs to check whether a given string is in
Any personal experience in overcoming web application performance hurdles? Any recommended strategies for improving
Any good recommendations for a platform agnostic (i.e. Javascript) grid control/plugin that will accept

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.