Glen Whitney
7b00b01856
All checks were successful
continuous-integration/drone/push Build is passing
42 lines
1.0 KiB
Plaintext
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
|