0
I 현재 입력 한 다음 함수 tt
를 작성할 수있는 방법 오류 :함수 인수
tt
에
runST
, 내부
s
가변 상태 함수
f
에 나사 결합 될 수 있다는 것을 생각
t :: Int
t = runST $ do
ref <- newSTRef 10
readSTRef ref
tt :: (STRef s a -> ST s a) -> Int
tt f = runST $ do
ref <- newSTRef 10
f ref
ttTest = tt readSTRef
, 하지만 컴파일러 오류가 다음과 같이 나에게 잘못되었다고 알려줍니다.
transform.hs:50:3: Couldn't match type `s' with `s1' …
`s' is a rigid type variable bound by
the type signature for tt :: (STRef s a -> ST s a) -> Int
at transform.hs:47:7
`s1' is a rigid type variable bound by
a type expected by the context: ST s1 Int
at transform.hs:48:8
Expected type: ST s1 Int
Actual type: ST s a
Relevant bindings include
ref :: STRef s1 a
(bound at transform.hs:49:3)
f :: STRef s a -> ST s a
(bound at transform.hs:48:4)
tt :: (STRef s a -> ST s a) -> Int
(bound at transform.hs:48:1)
In a stmt of a 'do' block: f ref
In the second argument of `($)', namely
`do { ref <- newSTRef 10;
f ref }'
transform.hs:50:3: Couldn't match type `a' with `Int' …
`a' is a rigid type variable bound by
the type signature for tt :: (STRef s a -> ST s a) -> Int
at transform.hs:47:7
Expected type: ST s1 Int
Actual type: ST s a
Relevant bindings include
ref :: STRef s1 a
(bound at transform.hs:49:3)
f :: STRef s a -> ST s a
(bound at transform.hs:48:4)
tt :: (STRef s a -> ST s a) -> Int
(bound at transform.hs:48:1)
In a stmt of a 'do' block: f ref
In the second argument of `($)', namely
`do { ref <- newSTRef 10;
f ref }'
모든 의견은 깊이 감사하겠습니다.
'tt :: (forall) s int -> ST Int) -> Int' – user2407038
아하, 그것은 순위 2 유형입니다. 고맙습니다. –