Github 传送门:https://github.com/bramblex/Smooth
线上试用:http://bramblex.github.io/Smooth/
# 异步的 delay 函数
delay = `(ms)=>(f)=>setTimeout(()=>f(ms),ms)`
# 将一个普通的函数封装成异步函数
mkasync = `(job)=>(f)=>{job();f()}`
# 将多个异步函数串联到一起
async f g = f g
# 以同步的方式写异步,每隔一秒依次输出 "hello" "world" "smooth"
asyncJob = with async do
delay 1000
mkasync _-> print $ "hello"
delay 2000
mkasync _-> print "world"
n <- delay 3000 # 还可以取得异步函数的数据
mkasync _-> print $ "smooth " + n
main _ = asyncJob _ -> print "done"
# 定义 `+` 符号
infixl 4 + add
add = `(x)=>(y)=>x+y`
# 定义 `<` 符号
infixl 6 < lt
lt = `(x)=>(y)=>x<y`
# 定义 `$` 符号,用来消除括号
infixr 0 $ app
app f x = f x
# 定义 `+` 符号
infixl 4 + add
add = `(x)=>(y)=>x+y`
# 定义 `<` 符号
infixl 6 < lt
lt = `(x)=>(y)=>x<y`
impFunc n =
let result = 0
let i = 0
while i < n
result = result + i
i = i + 1
decFunc n = if n < 0 then 0 else n + decFunc n