gluon-lang / gluon

A static, type inferred and embeddable language written in Rust.
https://gluon-lang.org
MIT License
3.2k stars 145 forks source link

Consider removing the IO monad #22

Open Marwes opened 8 years ago

Marwes commented 8 years ago

From writing the REPL I get the feeling that a strict language does not work that well with monadic action once a few actions are chained. Adding better syntax for monadic actions could maybe make it convenient enough but as the language isn't pure anyway it is likely better to remove the IO monad for now.

Marwes commented 8 years ago

Instead of removing the IO monad it may be worth adding some syntax sugar to make it easier to write monadic actions.

let test = 123
do let x = Some a
do None
None
do <expr> in <expr_2>
// Indentation works instead of in
do <expr>
<expr_2>
==>
<expr> >>= (\_ -> <expr_2>)
do let x = <expr> in <expr_2>
// Indentation works instead of in
do let x = <expr>
<expr_2>
==>
<expr> >>= (\x -> <expr_2>)
let opt =
    do let x = get map "abc"
    return x
match opt with
| Some y -> y
| None -> error "Expected Some"
brendanzab commented 8 years ago

One idea for making this easier in the repl might be to have an :x <expr> command for executing IO actions, like in the Idris repl.

Imo, I would err on the side of keeping the ugliness for now, and figure out how to make it prettier later.

Marwes commented 8 years ago

The repl already executes IO actions directly. Adding :x <expr> may make it more explicit though. I just mimicked ghci which also runs IO actions immediately.