Nathan Hüsken | 13 Apr 11:42 2013
Picon

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?

(Continue reading)

Niklas Larsson | 13 Apr 12:06 2013
Picon

Re: case switch covering all possible constructor but still fails



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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Daniel Trstenjak | 13 Apr 12:08 2013
Picon

Re: case switch covering all possible constructor but still fails


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
Nathan Hüsken | 13 Apr 19:49 2013
Picon

Re: case switch covering all possible constructor but still fails

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 <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

Gmane