2012-04-30 13 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

करता है यह 7.4 में जुड़े प्रकार चूक के साथ एक बग है .1। कुछ हफ्ते पहले, मुझे # हास्केल पर बताया गया था कि यह एक ज्ञात बग है जिसे तय किया गया है, लेकिन मुझे इसका उल्लेख जीएचसी ट्रैक पर नहीं मिला है।

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)