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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:30:40+00:00 2026-05-28T06:30:40+00:00

I am doing Problem 15 . Which states: (**) Replicate the elements of a

  • 0

I am doing Problem 15. Which states:

(**) Replicate the elements of a list a given number of times.

    Example:

    * (repli '(a b c) 3)
    (A A A B B B C C C)

    Example in Haskell:

    > repli "abc" 3
    "aaabbbccc"

My plan was to do something like this:

repli :: [a] -> Integer -> [a]

repli [] y = []

repli (x:xs) y | appendNo x y == [] = repli(xs) y
               | otherwise = appendNo x y : (x:xs)
               where
               appendNo :: a -> Integer -> [a]
               appendNo a 0 = []
               appendNo a y = a:appendNo a (y-1)

Where I would make a function called appendNo that returns a list of 1 element y times then append it to the original list. Then take the body of the list and repeat this process until there are no more body elements left. But, I get the error:

H15.hs:6:30:
    Couldn't match type `a' with `[a]'
      `a' is a rigid type variable bound by
          the type signature for repli :: [a] -> Integer -> [a] at H15.hs:3:1
    In the return type of a call of `appendNo'
    In the first argument of `(:)', namely `appendNo x y'
    In the expression: appendNo x y : (x : xs)
Failed, modules loaded: none.

6:30 is at the on the p in appendNo in this line:

           | otherwise = appendNo x y : (x:xs)

Ok thanks dave4420 I was able to figure it out by doing:

repli :: [a] -> Integer -> [a]

repli [] y = []

repli (x:xs) y = appendNo x y ++ repli(xs) y
               where
               appendNo :: a -> Integer -> [a]
               appendNo a 0 = []
               appendNo a y = a:appendNo a (y-1)
  • 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-28T06:30:40+00:00Added an answer on May 28, 2026 at 6:30 am
           | otherwise = appendNo x y : (x:xs)
    

    There is a type error in this line. So ask yourself:

    1. What is the type of appendNo x y?
    2. What is the type of (x:xs)?
    3. What is the type of (:)?

    Then you should be able to see why they don’t match up.

    If you still can’t see why they don’t match up, ask yourself

    1. What is the type of x?
    2. What is the type of xs?
    3. What is the type of (:)?

    Bear in mind that this time the types do match up.

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

Sidebar

Related Questions

The background to this problem is that I'm doing a computing project which involves
I am doing problem 7 of Project Euler. What I am supposed to do
i have strange problem doing reporting: i have numerous clients with different issued invoices.
can anyone help, i have problem doing a sort, I thought i had it
I'm having a problem with doing a sendSynchronousRequest failing. It only fails after I
OK. This problem is doing my head in. And I don't know if there
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
While doing some small regex task I came upon this problem. I have a
I'm having a problem with a POST I'm doing using the HttpWebRequest object from
I'm having a problem setting a cookie and doing a 302 redirect In chrome

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.