haskell - Why are these family instance declarations conflicting? -


i'm getting error code, , don't understand conflict is.

{-# language typefamilies, flexiblecontexts, flexibleinstances,     undecidableinstances #-}  import codec.gray (integraltogray, graytointegral) import data.list (foldl', unfoldr) import data.word (word8) import prelude hiding (read)  class gene g   type sequence g   write :: sequence g -> g -> sequence g   read :: sequence g -> maybe (g, sequence g)  instance (gene a, sequence ~ [k], integral k, gene k, sequence k ~ [k]) => gene [a]   type sequence [a] = sequence -- line 15   write xs gs = nothing -- stub   read xs = nothing -- stub   class (enum g, bounded g) => word8enum g   writeenum :: [word8] -> g -> [word8]   writeenum xs g = nothing -- stub    readenum :: g -> [word8] -> maybe (g, [word8])   readenum _ [] = nothing   readenum model (x:xs) = nothing -- stub  instance (word8enum g) => gene g   type sequence g = [word8] -- line 29   write = writeenum   read = readenum undefined 

when load code ghc, following error:

λ> :l amy4 [1 of 1] compiling main             ( amy4.hs, interpreted )  amy4.hs:15:8:     conflicting family instance declarations:       type sequence [a] -- defined @ amy4.hs:15:8       type sequence g -- defined @ amy4.hs:29:8 failed, modules loaded: none. 

in instance such as

instance (word8enum g) => gene g    ... 

ghc considers right hand side of instance arrow when matching instances. i.e., constraints aren't considered. gene g overlaps other instance, , in particular 1 gene [a] above.

overlapping instances allowed under conditions, overlapping associated types or type families not (they be, in restricted cases, in upcoming releases of ghc). therefore, error on 2 sequence declarations.


Comments