나는 Problem 15을하고있다.H-15에 문제가있다
(**) 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"
내 계획이 그런 짓을했다 : 어떤 상태 내가 한 요소 Y 시간의 목록을 반환 appendNo라는 함수를 만들 것
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)
는 원래 목록에 추가 . 그런 다음 목록의 본문을 가져 와서 더 이상 본문 요소가 없어 질 때까지이 과정을 반복하십시오.
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
이 줄에 appendNo
에 p
에에 있습니다 : : 그러나, 나는 오류가 나는 수행하여 알아낼 수 있었다 dave4420
| otherwise = appendNo x y : (x:xs)
확인 감사 :
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)
이이 직접 입력 오류와 관련이없는,하지만 고려 이 문제를 부분으로 분해하고 각 부분을 수행하기위한 도구가 있는지 확인하십시오. | 다시 함께 – Tyler
참고 이러한 문자 모인 1) 문자 반복 각 문자 2)에 뭔가를하고있는 N 시간 3) 그': 이 솔루션 3 개 일반적인 부분이 있습니다 appendNo x y == []'대문자는 필요 없습니다. 다른 경우는 충분히 잘 작동합니다. – Rotsor