compileCase :: Expr Var -> Var -> t -> [(AltCon,[Var],Expr Var)] -> Compile Expression
compileCase exp var typ alts = do
  e <- compileExp exp
  v <- compileVar var

  fmap (bind [v] e)
       (foldM (matchCon (Variable v)) (error "unhandled case")
              -- I have no idea why the DEFAULT case comes first from Core.
              (reverse (filter (not.isDefault) alts ++ filter isDefault alts)))

  where isDefault (con,_,_) = con == DEFAULT
compileCase :: Expr Var -> Var -> t -> [(AltCon,[Var],Expr Var)] -> Compile Expression
compileCase exp var typ alts = do
  e <- compileExp exp
  v <- compileVar var

  fmap (bind [v] e)
       (foldM (matchCon (Variable v)) (error "unhandled case")
              -- I have no idea why the DEFAULT case comes first from Core.
              (reverse (filter (not.isDefault) alts ++ filter isDefault alts)))

  where isDefault (con,_,_) = con == DEFAULT
compileCase exp var typ alts = do
  e <- compileExp exp
  v <- compileVar var

  fmap (bind [v] e)
       (foldM (matchCon (Variable v)) (error "unhandled case")
              -- I have no idea why the DEFAULT case comes first from Core.
              (reverse (filter (not.isDefault) alts ++ filter isDefault alts)))

  where isDefault (con,_,_) = con == DEFAULT