2016-10-27 14 views
0

私は現在、入力した次の関数ttを書くことができますどのようにエラー:関数の引数

私は ttrunST、内側 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 }' 

コメントは深く感謝されます。

+5

'tt ::(forStrings Int - > ST Int) - > Int' – user2407038

+0

Aha、それはランク2型です。ありがとうございました。 –

答えて

1

答えは擬似匿名で投稿されました:

tt :: (forall s . STRef s Int -> ST s Int) -> Int