case switch covering all possible constructor but still fails

Hey, I am trying to fix (or at least get my head around) this: https://github.com/valderman/haste-compiler/issues/27 Which is an issue of the haste haskell->javascript compiler. Doing so I encounter this problem which makes me think I am not understanding something fundamental here (and I believe this not to be haste specific)... OK, the problem is that this code: genAlt :: Bool -> JSVar -> JSVar -> StgAlt -> JSGen Config JSAlt genAlt tailpos scrut res (con, args, used, body) = do construct <- case con of DEFAULT -> return Def LitAlt l -> Cond <$> genLit l DataAlt c | Right tag <- genDataConTag c -> return $ Cond tag _ -> error "Bad data constructor tag generated!" Looking at StgAlt, I conclude that con must be of type AltCon, which is defined like this (from CoreSyn.lhs of the ghc source): data AltCon = DataAlt DataCon | LitAlt Literal | DEFAULT deriving (Eq, Ord, Data, Typeable) What I do not understand: The case switch covers all possibilities of AltCon. So how can this happen? Using trace, the con seemed to have the type "GHC.Integer.Type.S#" in the case of the erro. Thanks! Nathan

What I do not understand: The case switch covers all possibilities of AltCon. So how can this happen?
There is a guard on the DataAlt case so all alternatives doesn't have to be covered. -- Niklas

Oh, so obvious. That was it, thanks. On 04/13/2013 12:08 PM, Daniel Trstenjak wrote:
Hi Nathan,
DataAlt c | Right tag <- genDataConTag c -> return $ Cond tag
Are you sure, that genDataConTag always returns a 'Right'? If it returns a 'Left', than the pattern won't match.
Greetings, Daniel
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Daniel Trstenjak
-
Nathan Hüsken
-
Niklas Larsson