fostr/trans/haskell.str

42 lines
1.0 KiB
Plaintext

module haskell
imports libstrategolib signatures/-
signature
constructors
TopLevel: Ex -> Ex
rules
hs: TopLevel(x) -> $[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
[<hs>x]]
hs: Stdio() -> $[stdio]
hs: Int(x) -> x
hs: Sum(x) -> $[sum [<hs>x]]
hs: Receives(x, y) -> $[[<hs>x] `receives` [<hs>y]]
hs: [] -> $<[]>
hs: [x | xs] -> $<[<<hs>x><<hstail>xs>]>
strategies
// wrap expression in a toplevel and then apply code generation
haskell = !TopLevel(<id>); hs
// translate each element of a list, prepending each with ',', and concatenate
hstail = foldr(!"", \ (x,y) -> $<, <<hs>x><y>> \)
// Interface haskell code generation with editor services and file system
to-haskell: (selected, _, _, path, project-path) -> (filename, result)
with filename := <guarantee-extension(|"hs")> path
; result := <haskell> selected