forked from fika-lang/fika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.fi
71 lines (59 loc) · 1.39 KB
/
example.fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# A function definition
# that takes two args - an integer "a", another integer "b"
# and returns an integer.
fn sum(a: Int, b: Int) : Int do
a + b
end
# Here's a function that doesn't take any argument.
fn hello : String do
"World"
end
# This function returns a list of integers.
fn foo : List(Int) do
[1, 2, 3]
end
# This function returns a function reference.
fn sum_ref : Fn(Int, Int -> Int) do
&sum(Int, Int)
end
# Function references can be used to invoke the functions
# they refer.
fn call_sum_ref : Int do
sum_ref().(1, 2)
end
# true and false are keywords that are of type Bool
fn bool : Bool do
true
end
# Here's an example of the if-else expression.
# Notice that an if should always be followed by an else.
fn simple_if : String do
if true do
"this is a passing if!"
else
"you can't see me \m/"
end
end
# A tuple is a small group of values of different types.
# A tuple does not grow dynamically and is useful to hold
# values of different types together.
fn tuple : {Int,Bool} do
{1, true}
end
# Records are useful for holding data with known keys,
# for example, records from a table in a relational DB.
fn rec : {foo: List(Int)} do
{foo: [1, 2, 3]}
end
# Logical operator - or
fn or(a: Bool, b: Bool) : Bool do
a | b
end
# Logical operator - and
fn and(a: Bool, b: Bool) : Bool do
a & b
end
# Logical unary "not" operator
fn not(a: Bool) : Bool do
!a
end