Gleam: Annotating return types on anonymous functions

Created on 3 Mar 2020  路  1Comment  路  Source: gleam-lang/gleam

I just installed Gleam v0.7.0 and have been playing with it this afternoon - it's really fun, thanks so much for making it! As a big Elm fan, I've been wanting a similarly friendly statically typed language on the Beam for ages.

I have an anonymous function where I've annotated the type of the argument as follows:

pub fn example(x: Int) -> Int {
  let anon = fn(y: Int) {
    1 + y
  } 
  anon(x)
}

However, if I also try to annotate the return type:

pub fn example(x: Int) -> Int {
  let anon = fn(y: Int) -> Int {
    1 + y
  } 
  anon(x)
}

I get:

error: Syntax error

let anon = fn(y: Int) -> Int {
                      ^^ Unexpected token

Expected one of "{"

I'm not sure if this is expected behaviour? It seems unintuitive to be able to annotate the arguments of an anonymous function but not the return type.

good first issue help wanted

Most helpful comment

No specific reason why we don't have this, just an unimplemented feature! This would be a good one to get in the next release.

>All comments

No specific reason why we don't have this, just an unimplemented feature! This would be a good one to get in the next release.

Was this page helpful?
0 / 5 - 0 ratings