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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:19:09+00:00 2026-06-13T11:19:09+00:00

I have a question why this function cannot work with : but works with

  • 0

I have a question why this function cannot work with “:” but works with || and why “:” is replaced by ||
I mean why cannot write

contains xs (y:ys) = prefix xs (y:ys) : contains xs ys

 contains :: String -> String -> Bool
 contains [] _ = True
 contains _ [] = False
 contains xs (y:ys) = prefix xs (y:ys) || contains xs ys
  • 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-13T11:19:10+00:00Added an answer on June 13, 2026 at 11:19 am

    Key idea

    Use : to build up a list answer, || or && to build up a True/False answer, and + or * to build up a numerical answer. Think about what you’re combining – it doesn’t have to be : all the time.

    Detail

    I think you mean to ask why you can’t write

    contains xs (y:ys) = prefix xs (y:ys)  :  contains xs ys
    

    : is for gluing an element to the front of a list, so it has type a -> [a] -> [a]. This means you put a single thing on the left and a list on the right. You often use that in writing recursive functions, for example, you could define

    increase :: [Int] -> [Int]
    increase [] = []
    increase (x:xs) = x + 5 : increase xs
    

    Here x + 5 is an Int and increase xs is a [Int].

    Let’s look at your function. Its type is contains :: String -> String -> Bool so it takes a String, then a String, then gives you a Bool. Straight after the = you get prefix xs (y:ys). Now prefix has the same type: prefix :: String -> String -> Bool, so now we’ve given it xs and (y:ys) it’s giving us a Bool.

    At the end of the line we’ve got contains xs ys which is a Bool too, so if we put : between them we’ve got something a bit like

    False : True
    

    but we’re not allowed to do that because True isn’t a list. (Remember (:) :: a -> [a] -> [a].) You can do False:[True] (which would be [False,True], but that’s not what you want anyway.

    You need to check whether the xs is there – either at the front of (y:ys) or later on. The symbol for or is ||. So the code says

    xs is in (y:ys) if it’s at the front of it (prefix xs (y:ys)) or it’s somewhere in ys (contains xs ys).

    With the : (put-in-front-of symbol) in it it would say

    xs is in (y:ys) if it’s at the front of it (prefix xs (y:ys)), put that answer in front of these answers – it’s somewhere in ys (contains xs ys).

    which doesn’t make sense. That’s why you need or (||) not in-front-of (:).

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

Sidebar

Related Questions

Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
This question is based on the thread . I have the shell function function
I have a question regarding inheritance with function objects. I guess this must have
I have this question, just in theory. I do some query results and there
I have this question in which I have a SQL Server Compact Edition database
I have this question because I am not familiar latest generation of MS VS
I have this question: How could I call a codebehind method from jquery? I
I have this question relating to Lucene. I have a form and I get
I have this question, i am just throwing it out there. I am implementing
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The

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.