module haskell imports libstrategolib signatures/- util signature constructors TopLevel: Ex -> Ex rules /* Approach: Generate code from the bottom up. At every node, we create a pair of the implementation and necessary preamble of IO actions. We concatenate preambles as we go up. Finally, at the toplevel we emit the preamble before returning the final value. */ hs: TopLevel((c,p)) -> $[import System.IO data IOStream = StdIO stdio :: IO IOStream stdio = return StdIO receives :: Show b => IO a -> b -> IO a receives s d = do temp <- s putStr(show d) return temp main = do [p]return [c]] hs: Stdio() -> ("stdio", "") hs: Int(x) -> (x, "") hs: Sum((c,p)) -> ($[sum [c]], p) hs: Receives((c, p), (d, s)) -> ($[[c] `receives` [d]], (p,s)) hs: Enters((c, p), (d, s)) -> (c,d,(p,s),"fos") hsenter: (x, s, p, v) -> (v, [$[[p]let [v] = [x]], "\n", $[[s] `receives` [v]], "\n"]) hslist: x -> (x, x) brack: x -> $<[]> strategies // wrap expression in a toplevel and then apply code generation haskell = !TopLevel(); bottomup(try(hs <+ hslist)) // Interface haskell code generation with editor services and file system to-haskell: (selected, _, _, path, project-path) -> (filename, result) with filename := path ; result := selected