Skip to content

Latest commit

 

History

History
302 lines (246 loc) · 29.9 KB

QUICKREF.md

File metadata and controls

302 lines (246 loc) · 29.9 KB

Flix Quick Reference

Flix project This document gathers a few reference informations about the Flix programming language.
 

Hint: Read the document "Did You Know?" from the Flix documentation to know more about the Flix ecosystem.

Flix language features can be split into two categories :

  • features shared with other languages : ADTs and pattern matching, extensible records, type classes, HKTs, type inference, channel and process-based concurrency (like Go).
  • unique features : polymorphic effect system, region-based local mutation, purity reflection and first-class Datalog constraints.

Annotations

Flix annotations are defined in file language\ast\Ast.scala :

Definition Usage examples
@Benchmark benchmark/BenchmarkConstraint.flix
benchmark/BenchmarkList.flix
@Deprecated unused
@Experimental library/Benchmark.flix
library/Choice.flix
@Internal library/Debug.flix
@Lazy library/DelayList.flix
library/DelayMap.flix
@LazyWhenPure library/DelayList.flix
library/DelayMap.flix
@MustUse
@Parallel library/DelayMap.flix
@ParallelWhenPure library/DelayMap.flix
@Skip unused
@test library/TestApplicative.flix
library/TestArray.flix

Keywords

The list of Flix keywords is available from several locations :

Keyword Description Usage examples
alias Short-hand name for a type.
See type
library/File.flix
library\Fixpoint\Interpreter.flix
and library/Array.flix
library/Bool.flix
library/Eq.flix
as See import. library/Console.flix
case See match. library/Array.flix
catch See try. library/BigInt.flix
class library/Add.flix
def library/Add.flix
deref To access a reference cell. library/Array.flix
discard library/Array.flix
library/StringBuilder.flix
eff Only two usages found in Prelude.flix library/Prelude.flix
else See if. library/Array.flix
enum Flix enumerated types (recurive and polymorphic). library/Comparison.flix
false library/Array.flix
fix Used in Datalog constraints (i.e. in a #{...} block). library/Graph.flix
forall Used together with law library/Applicative.flix
force library/Bool.flix
foreach library/List.flix
forM library/BigInt.flix
from See select. library/Graph.flix
if Flix supports the usual if-then-else expression. library/Array.flix
import Interoperability with Java.
Usage cases are :
  • Import a Java class/interface (to create objects).
  • Access a Java instance method.
  • Create a Java instance
  • Access a Java static method.
 
 
inject library/Graph.flix
instance library/Add.flix
into See inject. library/Graph.flix
lat Datalog lattice variable (defined in a #{..} block). larger-examples/introduction.flix
law library/Applicative.flix
lawful Class modifier library/Applcative.flix
lazy Lazy evaluation of an expression library/DelayList.flix
let library/Array.flix
match library/Array.flix
mod Flix modules. library/Applicative.flix
not library/Bool.flix
null library/Files.flix
or
override See def. library/List.flix
par Flix parallelism. library/DelayMap.flix
pub library/Array.flix
query library/Graph.flix
ref library/Array.flix
region library/Array.flix
reify
reifyBool
reifyEff
reifyType
rel
resume Flix effect system (unused in library)
sealed
select See query. library/Graph.flix
set
solve library/Graph.flix
spawn library/DelayMap.flix
static See import. Char.flix
true
try For interoperability with Java, Flix supports the try-catch mechanism. library/BigDecimal.flix
type Unused in library
typematch library/Array.flix
upcast library/Prelude.flix
use library/Channel.flix
where See select. library/Graph.flix
with library/Console.flix
without Unused in library.
yield See forM and par. library/BigInt.flix
library/DelayMap.flix

Intrinsic Functions

Intrinsic functions can appear in Flix source code and are translated directly to the underlying JVM operations.

Note: Intrinsic functions are rewritten in method VisitExp in Scala source file ca/uwaterloo/flix/language/phase/Weeder.scala.

Intrinsic function Usage example
$ARRAY_LENGTHs$ library/Array.flix
$ARRAY_LOAD$ library/Array.flix
$ARRAY_NEW$ library/Array.flix
$ARRAY_STORE$ library/Array.flix
$BOOL_EQ$ library/Eq.flix
$BOOL_NEQ$ library/Eq.flix
... ...

Built-in Functions

The Flix built-in functions are defined in file Flix.scala (value coreLibrary) :

Namespace Functions
Bool
Boxable
Boxed
Channel buffered, recv, send, timeout, unbuffered
Comparison
Debug
Eq
Hash
Reflect default
Sendable
Order
Thread
Time
ToString

Standard Functions

The Flix standard functions are defined in file Flix.scala (value standardLibrary) :

Namespace Function(s)
Array head, isEmpty, last, toList, etc.
Assert eq
Benchmark runAll, runBenchmark, runBenchmarkOnce, loop
Bigdecimal
BigInt fromString, min, toString, etc.
Chain
Char isLetter, isLowerCase, etc.
Choice Defines the enumeration values Absent and Present.
Console readLine, print, printLine
Environment getEnv, getProp, getVar
File accessTime
Float32
Float64 64-bit float
Int8 8-bit integer
Int16
Int32
Int64 bitCount, factorial, fromString, log2
Iterable enumerator, iterator
Iterator isEmpty, next, range, etc.
List head, isEmpty, toString
StringBuilder append!, length, toString
Concurrent/Channel
Concurrent/Condition Condition functions are await, signal, etc.

Predefined Operators

Operator Description
<-
=>
@
:
::: The infix operator ::: is an alias for List.append(xs, ys).

Flix Grammar (WIP)

GitHub: src\ca\uwaterloo\flix\language\phase\Parser.scala

Program       = UsesOrImports { Declaration }

UsesOrImports = ( Use | Import ) { Use | Import }

Use           = use ( NQualifiedType '.' NTag
                   | NQualifiedType '.{' { TagAndAlias1 { ',' TagAndAlias1 } } '}'
                   | NNamespace '.' UseName
                   | NNamespace '.{' NameAndAlias1 { ',' NameAndAlias1 } } '}'
                   ) ';'

TagAndAlias1  = NTag [ '=>' NTag ].

NameAndAlias1 = UseName [ '=>' UseName ].

UseName       = NLowerCaseName | NUpperCaseName
              | NGreekName | NMathName | NOperatorName. 

Import      = import NJavaName
              [ '.{' { NameAndAlias { ',' NameAndAlias } } '}' ].

Declaration = Namespace | Def | Law | Enum | RestrictedEnum
            | TypeAlias | Class | Instance | Effect.

Namespace   = mod NNamespace '{' Program '}'.

Def         = Documentation Annotations Modifiers
              def NDefinition TypeParams FormalParamList ':' TypeAndEffect OptTypeConstraintList '=' Stmt.

Sig         = Documentation Annotations Modifiers
              def NDefinition TypeParams FormalParamList ':' TypeAndEfect OptTypeConstraintList [ '=' Stmt ].

Law         = Documentation Annotations Modifiers
              law NDefinition ':'

Enum        = Documentation Annotations Modifiers
              enum NType TypeParams [ TTuple ]
              Derivations Body.

TypeAlias   = Documentation Modifiers
              type alias NType TypeParams '=' Type.

Relation    = Documentation Modifiers
              rel NPredicate TypeParams AttributeList.

Lattice     = Documentation Modifiers
              lat NPredicate TypeParams AttributeList.

Class       = Documentation Annotations Modifiers
              class NClass '[' TypeParam ']'
              [ '{' Law | Sig '}' ].

Instance    = Documentation Modifiers
              instance NQualifiedClass '[' Type ']' OptTypeConstraintList [ '{' { Def } '}' ].

Effect      = Documentation Modifiers
              eff NEffect TypeParams [ '{' { Op } '}' ].

TypeParams  = [ '[' TyeParam { ',' TypeParam } ']' ].

TypeParam   = NVariable [ ':' Kind ].

Compiler Options

GitHub: test\ca\uwaterloo\flix\TestMain.scala

Footnotes

[1] Flix versus Scala

Extract from the Flix FAQ :

Flix looks quite similar to Scala. How are the two languages related?

Flix borrows a lot of syntax from Scala, hence the two languages have a similar feel. We think Scala made many good design choices with respect to syntax, including:
a) the use of short keywords,
b) the x : T syntax for type annotations,
c) the List[Int32] syntax for type parameters, and
d) if, match, etc. as expressions.

Other than syntax, the two languages are very different:
  • Scala is object-oriented, Flix is not.
  • Scala has sub-typing, Flix does not.
  • The Scala type system is unsound and has imperfect type inference, whereas the Flix type system is both sound and supports type inference.

mics/May 2024