Skip to content

Commit

Permalink
Brace positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Mar 31, 2020
1 parent db57e5d commit c20ad96
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions effects.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,30 @@ import gleam/result
// A function annotated with the IO effect. If the effect annotation was
// neglected it would be inferred by the fact that io.read_line has the IO
// effect
pub fn read_string() effect(IO) -> String
{
pub fn read_string() effect(IO) -> String {
io.read_line()
}

// This function uses the Assert effect
pub fn unsafe_unwrap(x: Result(a, e)) effect(Assert) -> a
{
pub fn unsafe_unwrap(x: Result(a, e)) effect(Assert) -> a {
assert Ok(a) = x
a
}

// This function calls a function that has the IO effect and another that has
// the Assert effect, so it has both the IO and Assert effects. If the
// annotation was not given this would be inferred.
pub fn get_content() effect(IO, Assert) -> String
{
pub fn get_content() effect(IO, Assert) -> String {
read_line() |> unsafe_unwrap
}

// This function's effect annotation says that it may have any effects `a`, but
// that `a` effects do not include the effects IO or Assert.
pub fn render_view(view: fn() -> String) effect(a | -IO, -Assert) -> String
{
pub fn render_view(view: fn() -> String) effect(a | -IO, -Assert) -> String {
view()
}

pub fn main() effect(IO, Assert) -> String
{
pub fn main() effect(IO, Assert) -> String {
// This won't compile as in this case the effects of IO and Assert are
// happening inside the call to render_view, which is annotated as not having
// the IO or Assert effects
Expand Down

0 comments on commit c20ad96

Please sign in to comment.