How to combine a map and replicate over an array of integers

For a school exercise, I need to create a series of characters with a given array of numbers. given [3,3,2,1]output "+===+===+==+=+". My approach would be to use mapand replicate"=" in the array, then intercalate"+" and, finally, concatan array for one line.

My solution is something like this (with constant knee errors)

printLine arr = map (replicate "=") arr >>> intercalate '*' >>> concat

What is the correct syntax? or shouldn't i use the card at all?

+4
source share
1 answer

you're on the right track, you just messed up the functions a bit:

  • replicate n n-times ( , flip , )
  • , , , Char String ('='VS "=") - ( :t intercalate Hoogle) : String ~ [Char]!
  • intercalate , concat

:

eqSigns :: Int -> String
eqSigns n = replicate n '='

mixIn :: [Int] -> String
mixIn = intercalate "+" . map eqSigns

, ;)


flip :

mixIn :: [Int] -> String
mixIn = intercalate "+" . map (flip replicate '=')

PS: - ML/F #?

+4

Source: https://habr.com/ru/post/1606163/


All Articles