tcr / corollary

Cross-compiler from Haskell to Rust, plus parser-haskell.
73 stars 5 forks source link

Not all `Just` `Nothing` translated properly. #54

Closed tcr closed 7 years ago

tcr commented 7 years ago

See Idiomatic.hs:

tailExpr :: Rust.Expr -> Maybe (Maybe Rust.Expr)
-- If the last statement in this block is a return statement, extract
-- its expression (if any) to the final expression position.
tailExpr (Rust.Return e) = Just e
-- If the last statement is a block, that's a tail-block.
tailExpr (Rust.BlockExpr b) = Just (Just (Rust.BlockExpr (tailBlock b)))
-- If the last statement is an if-expression, its true and false blocks
-- are themselves tail-blocks.
-- TODO: treat match-expressions like if-expressions.
tailExpr (Rust.IfThenElse c t f) = Just (Just (Rust.IfThenElse c (tailBlock t) (tailBlock f)))
-- Otherwise, there's nothing to rewrite.
tailExpr _ = Nothing