0

My problem is to build a function that given a person and an amount of hours(Integer) it adds "erp" at the start of the name, but the "r" must multiply the amount of hours.

My function must be of the type:

drink :: Integer -> Client -> Client

here it´s an example:

drink 5 (Aperson name _ _) = "errrrrpname"

I know how to do the concatenation but i dont know how to multiply the "r" the amount of time.

3
  • Can you make a function that just takes in a String s and an integer n and gives back the String that is s multiplied by n (without dealing with the Client stuff)? I would start there. Commented Apr 13, 2017 at 16:16
  • Then why didn't you title your question to reflect the fact that you are interested in "string multiplication" (rather than mere "concatenation")? Commented Apr 13, 2017 at 16:29
  • 1
    If you want to use a standard library function (instead of implementing it yourself), there is replicate. Commented Apr 13, 2017 at 16:31

1 Answer 1

1

Repeating a char

take 10 $ repeat 'a'     -- "aaaaaaaaaa"

Repeating a string

[1..10] >>= (\_ -> "x-") -- "x-x-x-x-x-x-x-x-x-x-"
[1..10] >> "x-"          -- "x-x-x-x-x-x-x-x-x-x-"
Sign up to request clarification or add additional context in comments.

2 Comments

While both of these work, neither one is really appropriate for what he is doing.
@Lazersmoke I agree on that these are suboptimal, but they work, have the correct complexity, and are reasonably readable. This is a good answer in my eye, and would be very good if only the library didn't contain replicate(M). But that's not a huge deal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.