Overview of the language elements of Fold.
- 1 Introduction
- 2 Comments
- 3 Literals
- 4 Expressions
- 5 Control Flow
- 6 Bindings
- 7 Types
- 8 Collections
- 9 Functions
- 10 Modules
- 11 Error Handling
- 12 Metaprogramming
-- This is a single-line comment.
{{ This is a multi-line comment.
{{ Multi-line comments can be nested. }} }}
-- Booleans
True False
-- Integers
42 1_000_000
Int.min Int.max
-- Floats
3.14 0.999
nan infinity
-- Characters
'x' '\n' '0xFF'
-- Strings
"Hello, World!"
"""
This is a multi-line string.
Multi-line strings can contain "quotation marks".
"""
-- Symbols
`hello `foo `x
-- Boolean operators are [&&], [||] and [not].
True && not (True || False)
(2 + 4) * (4 ** 2 - 9)
"hello" ++ " " ++ "world" ++ "!"
-- Definitions
-- Variables
-- Let Expressions
-- Where Expressions
print ("The squre root of 81 is %d" % Math.sqrt 81)
x = 10
print (if (x == 10) "yeah" else: "nope")
def sum_of_squares (x::Int) (y::Int) -> Int
let
x2 = x * x
y2 = y * y
in
x2 + y2
end
def sum_of_squares x y = x * x + y * y
-> sum_of_squares 3 4
:: Int = 25