가상의 하스켈 코드는 정확히 무엇이 틀렸습니까? 내 머리 속에서 컴파일하면 "1"이 출력됩니다.하스켈 및 Rank-N 다형성
foo :: forall a. forall b. forall c. (a -> b) -> c -> Integer -> b
foo f x n = if n > 0 then f True else f x
bar :: forall a. a -> Integer
bar x = 1
main = do
putStrLn (show (foo bar 1 2))
GHC는 불평 :
$ ghc -XRankNTypes -XScopedTypeVariables poly.hs
poly.hs:2:28:
Couldn't match expected type `a' against inferred type `Bool'
`a' is a rigid type variable bound by
the type signature for `foo' at poly.hs:1:14
In the first argument of `f', namely `True'
In the expression: f True
In the expression: if n > 0 then f True else f x
poly.hs:2:40:
Couldn't match expected type `Bool' against inferred type `c'
`c' is a rigid type variable bound by
the type signature for `foo' at poly.hs:1:34
In the first argument of `f', namely `x'
In the expression: f x
In the expression: if n > 0 then f True else f x
이 무엇을 의미합니까? Rank-N 다형성이 유효하지 않습니까? (면책 조항 : 저는 Haskell 프로그래머가 아닙니다. 그러나 OCaml은 그러한 명시적인 타입 서명을 지원하지 않습니다.)
아. 모두의 나의 아주 좋아하는 컴파일러 :) –