Created
December 23, 2019 14:41
-
-
Save zypeh/8aff5e8ff7cf5f5a0a42f36ab95b656f to your computer and use it in GitHub Desktop.
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
-- comments | |
--| doc comments, should support latex (my dream) | |
--|prefix| prefixed comments | |
--[block comment]-- | |
--[prefix| prefixed block comment]-- | |
[1, 2, 3] -- lists | |
1 :: 2 :: 3 :: [] -- list | |
-- Types, should starts with uppercase letters | |
Bool | |
-- Sum Types | |
Sum = Bool | Int | |
a := 123 -- variable assignment (type inferenced) | |
a : Int = 123 -- variable assginment (with type declarations) | |
-- Records | |
record = { a: 32, b: True } | |
-- Tuples, behaves like a record with numericc field names. | |
tuples = (32, True) | |
-- As you see, there is no `let` statement in root level of the file. | |
-- declare a function | |
plus2 (x: i32) : i32 = { x + 2 } | |
plus4 (x: i32) : i32 = plus2 (plus2 x) | |
-- local variables | |
plus8 (x: i32) : i32 = { | |
let y = plus4 (x) -- (x) can be reduced to x, unless it is (x,) | |
let z = plus2 x | |
y + z | |
} | |
-- yes it is newline sensitive, and I try to avoid semicolon as mandatory | |
-- because some of the keyboard layouts are hard to type `;`, if they want | |
-- to make a term multiline, then use parenthesis. | |
someFunc a b c d e f | |
-- into | |
someFunc ( | |
a -- there is no comma here, whitespaces or newline is fine | |
b | |
c | |
d | |
e | |
f | |
) | |
-- arrays | |
-- it is always `[n-ary]type`, so you can make it nested | |
a : [3][2]Int -- means there is 3 array that contains 2 element of Int | |
= [[1, 2], [3, 4], [5, 6]] | |
-- but this is invalid [[1, 2, 3], [4, 5, 6]] | |
-- random access of data | |
a : [3][2]i32 = [[1, 2], [3, 4], [5, 6]] | |
a[1] -- [1, 2] | |
t := (3, 4) | |
t.2 -- 4 | |
x = { x: 123, y: True } | |
x.y -- True | |
-- closure | |
\(x:type) (y:type) => body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment