2012-04-30 7 views
9

기본 제약 조건을 정의 할 때 이상한 문제가 발생했습니다. 제한 조건이 단위이면 기본 인스턴스가 선택되지 않습니다. 다른 모든 경우에는 예상대로 작동합니다.기본 제약 조건 종류가 무시됩니다.

{-# LANGUAGE TypeFamilies, ConstraintKinds #-} 
import qualified GHC.Exts as E 

class Expression a where 
    type Constr a v :: E.Constraint 
    --type Constr a v =()   -- with this line compilation fails 
    --type Constr a v = v ~ v  -- compiles 
    wrap :: Constr a v => a -> Maybe v 

instance Expression() where 
    wrap() = Just undefined 

main = print (wrap() :: Maybe Int) 

누군가 유형 검사기 동작의 이유를 명확히 할 수 있습니까?

+1

'v' 유형과 연관 유형 매핑이 해결되는 항목이 없기 때문에 추측 하시겠습니까? – ivanm

+2

아마도 : [ConstraintKinds 및 기본 관련 빈 제약 조건] (http://comments.gmane.org/gmane.comp.lang.haskell.glasgow.user/21058) – hammar

답변

4

않습니다 .1. 몇 주 전 #haskell에서 버그가 수정되었음을 알았지 만 GHC trac에서 해당 버그를 찾을 수 없습니다.

4
정말

하지 대답,하지만이하지에 대한 ConstraintKinds

class Expression a where 
    type Type a v 
    type Type a v =() 
    wrap :: (Type a v) ~() => a -> Maybe v 

instance Expression() where 
    wrap() = Just undefined 

main = print (wrap() :: Maybe Int) 

를 컴파일되지 않습니다,하지만

class Expression a where 
    type Type a v 
    type Type a v = v 
    wrap :: (Type a v) ~ v => a -> Maybe v 

instance Expression() where 
    wrap() = Just undefined 

main = print (wrap() :: Maybe Int) 

이 7.4에 관련된 유형의 디폴트와 버그