그래서 사용자가 문자열에 "아니오"또는 "아니오"를 입력했는지 감지하려고하는 haskell에서 다음 코드를 시도했습니다. 또한 [[Char]]를 String으로 대체하려고 시도했지만 컴파일 오류가 발생합니다.Haskell 함수에서 문자열을 전달하는 중 오류가 발생했습니다.
wantGifts :: [[Char]] -> [[Char]]
wantGifts st = [if (x == "No" || x== "no") then "No gifts given" else "But why" | x <- st, x == head st]
위의 코드는 컴파일하지만 난 그것에 문자열을 전달하면 오류 메시지가 반환 밀접 wantGifts
의 종류에
*Main> wantGifts "no I dont"
<interactive>:8:11:
Couldn't match type ‘Char’ with ‘[Char]’
Expected type: [[Char]]
Actual type: [Char]
In the first argument of ‘wantGifts’, namely ‘"no I dont"’
In the expression: wantGifts "no I dont"
In an equation for ‘it’: it = wantGifts "no I dont"
오류는 함수가 문자열 (목록을 기대하고 있다고리스트의-목록 -of-chars). 그러나 당신은 하나를 넘어 가지 않습니다. – chi