Last active
October 18, 2019 14:10
-
-
Save ronchaine/036b89c5c4bda38525587898ac5d7972 to your computer and use it in GitHub Desktop.
flow example
This file contains hidden or 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
# syntax stuff | |
# declare type kind | |
deftype Integer as | |
{ | |
int8 or | |
int16 or | |
int32 or | |
int64 or | |
int128 or | |
uint8 or | |
uint16 or | |
uint32 or | |
uint64 or | |
uint128 | |
} | |
# short form | |
deftype Float as float32 or float64; | |
# declare structure type | |
deftype ValueStruct | |
{ | |
int32 value1; | |
int32 value2; | |
} | |
deftype Number as Integer or Float; | |
# Basic prototypes | |
func A: int32 input -> int32 output; | |
func A: int32 i0, int32 i1 -> int32 output; | |
# Multiple return values (i.e. return tuple) | |
func A: int32 input -> int32 o0, int32 o1; | |
# Can be used with | |
ValueStruct b = A(input) as ValueStruct; | |
# or | |
int32 a, int32 b = A(input); | |
# Generics | |
func A: Integer input -> int64 output; | |
# Get output type from input | |
func A: Integer input as T -> T output; | |
# Casting (required) | |
int8 a = 10; | |
mutable int16 b; | |
b = a as int16; | |
# Reserved symbols: | |
# : (description) | |
# -> (implication, result) | |
# , (separator) | |
# . (member access) | |
# () (arguments) | |
# [] (access) | |
# {} (block) | |
# These symbols may not appear in identifiers or operator names | |
# also possible to do this, anything that has binop +(T a, T b) -> T | |
# will qualify as Summable | |
deftype Summable as | |
{ | |
with T as Any require binop +(T a, T b) -> T; | |
} | |
# Statically check type | |
if int32 is Summable | |
{ | |
# do something | |
} | |
# Tagged unions | |
deftype Result either ValueType or ErrorType; | |
# Structs can hold functions | |
deftype FuncContainer | |
{ | |
pure func a: int32 forward -> int32 b; | |
} | |
# Defining / overloading operators | |
with T as Integer binop +(T a, T b) precedence 10 -> T; | |
# Hello world | |
func main: string[] args -> int32 | |
{ | |
# extern "C" call printf("hello world!\n"); | |
# or | |
# std::format_to(stdout, "hello world!\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment