올바른 버전으로 내 코드를 반복, 나는 다음과 호기심을 가로 질러 온 반면 :하자 - 이름 바꾸기 기능 구분 코드를
는{-# LANGUAGE RankNTypes #-}
module Foo where
import Data.Vector.Generic.Mutable as M
import Control.Monad.Primitive
-- an in-place vector function with dimension
data DimFun v m r =
DimFun Int (v (PrimState m) r -> m())
eval :: (PrimMonad m, MVector v r) => DimFun v m r -> v (PrimState m) r -> m()
eval = error ""
iterateFunc :: (PrimMonad m, MVector v r)
=> (forall v' . (MVector v' r) => DimFun v' m r) -> DimFun v m r
iterateFunc = error ""
f :: (PrimMonad m, MVector v r)
=> DimFun v m r
f = error ""
iteratedF :: (MVector v r, PrimMonad m)
=> v (PrimState m) r -> m()
iteratedF y =
let f' = f
in eval (iterateFunc f') y
이 코드는 컴파일되지 않습니다 :
Testing/Foo.hs:87:14:
Could not deduce (MVector v0 r) arising from a use of ‘f’
from the context (MVector v r, PrimMonad m)
bound by the type signature for
iteratedF :: (MVector v r, PrimMonad m) =>
v (PrimState m) r -> m()
at Testing/Foo.hs:(84,14)-(85,39)
The type variable ‘v0’ is ambiguous
Relevant bindings include
f' :: DimFun v0 m r (bound at Testing/Foo.hs:87:9)
y :: v (PrimState m) r (bound at Testing/Foo.hs:86:11)
iteratedF :: v (PrimState m) r -> m()
(bound at Testing/Foo.hs:86:1)
In the expression: f
In an equation for ‘f'’: f' = f
In the expression: let f' = f in eval (iterateFunc f') y
Testing/Foo.hs:88:26:
Couldn't match type ‘v0’ with ‘v'’
because type variable ‘v'’ would escape its scope
This (rigid, skolem) type variable is bound by
a type expected by the context: MVector v' r => DimFun v' m r
at Testing/Foo.hs:88:14-27
Expected type: DimFun v' m r
Actual type: DimFun v0 m r
Relevant bindings include
f' :: DimFun v0 m r (bound at Testing/Foo.hs:87:9)
In the first argument of ‘iterateFunc’, namely ‘f'’
In the first argument of ‘eval’, namely ‘(iterateFunc f')’
Failed, modules loaded: none.
을하지만, 내가 변경하는 경우 iteratedF
에서
iteratedF y = eval (iterateFunc f) y
의 정의는 GHC 7.8.2로 컴파일됩니다. 이 질문은 이상한 모양의 서명이나 데이터 유형에 관한 것이 아니라 단순히 다음과 같습니다. f
에서 f'
으로 이름을 바꾼 이유는 무엇입니까? 이것은 저에게 버그가되어야하는 것 같습니다.
다음은 무시 무시한 단일 변체 제한의 또 다른 경우이다. – crockeea
나는 이름 바꾸기가 순수 하스켈 98에서 문제를 일으킬 수 없다고 생각하지 않는다.''f f = show in f 1 ++ f True'를 고려하자. –