Javascript의 "indexOf"에 상응하는 함수를 쓰려고합니다. (문자열의 문자 색인을 가져 오는 것), 재귀 함수를 호출 할 때 문제가 있습니다. 이건 내 코드입니다더 많은 매개 변수를 사용하는 재귀
Couldn't match expected type `Int'
with actual type `a0 -> [a0] -> Int'
In the return type of a call of `get_index'
Probable cause: `get_index' is applied to too few arguments
In the expression: get_index (index + 1 char str)
In an equation for `get_index':
get_index index char str
| index < 0 || index >= (length str) = - 1
| (str !! index) == char = index
| otherwise = get_index (index + 1 char str)
Failed, modules loaded: none.
:
이
오류입니다index_of char str =
get_index 0 char str
get_index index char str
| index < 0 || index >= (length str) = -1
| (str !! index) == char = index
| otherwise = get_index(index + 1 char str)
먼저 함수의 목적은 인덱스 매개 변수, 더 아무것도 재귀 전화를 전적으로, 내가 가지고있는 문제는 두 번째 함수에서 재귀.
실수로'get_index'를 재귀 호출합니다. 'get_index'의 마지막 줄에서,'get_index (index + 1) char str', _not_'get_index (index + 1 char str)'을 의미했습니다. 그리고 나서 기능은 예상대로 작동합니다! – Alec
네, 효과가있었습니다. 너보다 훨씬! – Marcus