tcr / corollary

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

Support generators #66

Open tcr opened 7 years ago

tcr commented 7 years ago

When a generator is encountered in code, we just output it as a /* TODO: Generator */ comment. These are used a few times around the libraries we're porting so we should handle them intelligently.

To repro, save this as test.hs:

module Test()
where

example :: ()
example = do
    let a = [(i,j) | i <- [1,2], j <- [1..4] ]

Running cargo run --manifest-path corollary/Cargo.toml -- test.hs currently outputs this:

// Original file: "test.hs"
// File auto-generated using Corollary.

#[macro_use] use corollary_support::*;

pub fn example() -> () {
    /*do*/ {
        let a = /* Expr::Generator */ Generator;

    }
}

Possibly expected output, using Rust's itertools crate:

pub fn example() -> () {
    /*do*/ {
        let a = iproduct!(vec![1, 2].into_iter(), (1..4).into_iter()).map(|(i, j)| (i, j)).collect::<Vec<_>>();
    }
}