-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cdce7b
commit 475977a
Showing
15 changed files
with
65 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
fn main() { | ||
let local = 10; | ||
let assign_capture = fn () { | ||
let assign_capture = \() { | ||
set local = 20; | ||
}; | ||
{} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
fn main() -> i32 { | ||
let f = fn () -> f32 { | ||
let f = \() -> i32 { | ||
return 10; | ||
}; | ||
return 10.0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
global x : i32 = 10.0 | ||
global my_fn : fn (i32) -> i32 = fn (x : f32) -> f32 { x } | ||
global my_fn : fn (i32) -> i32 = \(x : f32) -> f32 { x } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import log : fn (i32) -> unit from log | ||
|
||
fn main() { | ||
let x = (fn (x : i32) -> i32 { x + 1 })(10); | ||
let x = (\(x : i32) -> i32 { x + 1 })(10); | ||
log(x); | ||
|
||
let twice = { | ||
fn (f : fn (i32) -> i32) -> fn(i32) -> i32 { | ||
fn (x : i32) -> i32 { | ||
\(f : fn (i32) -> i32) -> fn(i32) -> i32 { | ||
\(x : i32) -> i32 { | ||
f(f(x)) | ||
} | ||
} | ||
}; | ||
let add1 = fn (x : i32) -> i32 { x + 1 }; | ||
let add1 = \(x : i32) -> i32 { x + 1 }; | ||
log(twice(add1)(3)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Anonymous functions (Lambdas) | ||
|
||
Lambdas are nameless functions that can appear in expression position. They | ||
capture variables from their environment. Value types are copied when captured | ||
and trying to `set` them results in a type error. | ||
|
||
They are defined using a `\` followed by a parameter list: | ||
|
||
``` | ||
\(x : i32) -> i32 { x + 1 } | ||
``` | ||
|
||
When a lambda appears in checking position its argument and result types | ||
can be ommitted and will be inferred. | ||
|
||
``` | ||
let x : i32 = (\(y) { y + 1 })(2); | ||
``` | ||
|
||
Lambdas are always monomorphic. |