[Haskell-cafe] Bug in GADT Implementation?

Dominic Steinitz dominic.steinitz at blueyonder.co.uk
Sat May 26 13:10:42 EDT 2007


I would expect

foo r@(Range BITSTRING _ _) x = []

to give an error but it doesn't. Writing

t = Range BITSTRING

gives one so why not the pattern match?

Dom.

data BitString = BitString [Bool]
   deriving Show

data ConstrainedType :: * -> * where
   INTEGER         :: ConstrainedType Int
   BITSTRING       :: ConstrainedType BitString
   Seq             :: ConstrainedType a -> ConstrainedType b ->
ConstrainedType (a,b)
   Range           :: Ord a => ConstrainedType a -> a -> a ->
ConstrainedType a

foo :: ConstrainedType a -> a -> [Int]
foo BITSTRING (BitString x) = map fromEnum x
foo INTEGER x = [x]
foo r@(Range INTEGER _ _) x = [upperInt r,x]
foo r@(Range BITSTRING _ _) x = []

r1 = Range INTEGER 20 40
r2 = Range r1 25 45

upperInt :: ConstrainedType Int -> Int
upperInt INTEGER = 256
upperInt (Range t l u) = min u (upperInt t)



More information about the Haskell-Cafe mailing list