I'm getting an error for this code, and I don't understand where the 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 where
type Sequence g
write :: Sequence g -> g -> Sequence g
read :: Sequence g -> Maybe (g, Sequence g)
instance (Gene a, Sequence a ~ [k], Integral k, Gene k, Sequence k ~ [k]) => Gene [a] where
type Sequence [a] = Sequence a -- LINE 15
write xs gs = Nothing -- stub
read xs = Nothing -- stub
class (Enum g, Bounded g) => Word8Enum g where
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 where
type Sequence g = [Word8] -- LINE 29
write = writeEnum
read = readEnum undefined
When I load my code into GHC, I get the following error:
λ> :l amy4
[1 of 1] Compiling Main ( amy4.hs, interpreted )
amy4.hs:15:8:
Conflicting family instance declarations:
type Sequence [a] -- Defined at amy4.hs:15:8
type Sequence g -- Defined at amy4.hs:29:8
Failed, modules loaded: none.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…