Skip to content

Latest commit

 

History

History
228 lines (167 loc) · 4.33 KB

Language Overview.md

File metadata and controls

228 lines (167 loc) · 4.33 KB

Language Overview

Overview of the language elements of Fold.

1 Introduction

2 Comments

-- This is a single-line comment.

{{ This is a multi-line comment.

{{ Multi-line comments can be nested. }} }}

3 Literals

-- 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

4 Expressions

4.1 Basic Operations

-- Boolean operators are [&&], [||] and [not].
True && not (True || False)

(2 + 4) * (4 ** 2 - 9)

"hello" ++ " " ++ "world" ++ "!"

4.2 Bindings

-- Definitions

-- Variables

-- Let Expressions

-- Where Expressions

4.3 Blocks

4.4 Function Application

print ("The squre root of 81 is %d" % Math.sqrt 81)

6 Control Flow

6.1 Conditionals

6.2 If Expressions

x = 10
print (if (x == 10) "yeah" else: "nope")

6.3 When Expressions

6.2 Pattern-matching

6.2.1 Match Expressions

6.2.2 Conditional Matching

6.2.3 Pattern Views

6.3 Exceptions

6.4 Loops

6.4.1 While Loops

6.4.2 For Loops

6.4.3 Recursion

7 Types

7.1 Primitive Types

7.2 Tuples

7.3 Records

7.4 Anonymous Records

7.5 Parametric Types

7.6 Union Types

7.7 Abstract Data Types

8 Collections

8.1 Lists

8.2 Sets

8.3 Arrays

8.4 Dicts

9 Functions

9.1 Anonymous Functions

9.2 Function Definitions

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

9.3 Named Arguments

9.4 Custom Operators

10 Modules

10.1 Module Definitions

10.2 Signatures

10.3 Type Modules

10.4 Module Extensions

10.5 Module Functions

10.6 Imports and Includes

11 Error Handling

12 Metaprogramming

12.1 Meta Attributes

12.2 Static Introspection

12.3 Macros