나는 하스켈에 새로운 프로그래밍이며, 다소 혼란 스럽다. 익명의 기능을 왜 카레로 만들 수 없습니까, 아니면 가능합니까?카레 익명의 함수
나는 다음과 같은 코드 조각 한 :이처럼 쓸
largestDivisible :: (Integral a) => a -> a
largestDivisible x
| x <= 0 = error "NOT A VALID VALUE"
| otherwise = head (myFilter (f x) [x-1, x-2..1])
where f x y= x `mod` y == 0
을 때 :
largestDivisible :: (Integral a) => a -> a
largestDivisible x
| x <= 0 = error "NOT A VALID VALUE"
| otherwise = head (myFilter (\ x y = x `mod` y == 0) [x-1, x-2..1])
그럼 다음과 같은 오류 나는 GHCi에로드하려고받을 경우 ,
ListStuff.hs:85:35: error:
• Couldn't match expected type ‘Bool’ with actual type ‘a -> Bool’
• The lambda expression ‘\ x y -> (mod x y == 0)’
has two arguments,
but its type ‘a -> Bool’ has only one
In the first argument of ‘myFilter’, namely
‘(\ x y -> (mod x y == 0))’
In the first argument of ‘head’, namely
‘(myFilter (\ x y -> (mod x y == 0)) [x - 1, x - 2 .. 1])’
• Relevant bindings include
x :: a (bound at ListStuff.hs:83:19)
largestDivisible' :: a -> a (bound at ListStuff.hs:83:1)
Failed, modules loaded: none.
왜 '필터'대신 'myFilter'를 사용 했습니까? 그리고 필자는'filter' 대신'find'를 사용하는 것이 더 적절하다고 생각합니다. – freestyle