Flix Quick Reference ↩
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.
Flix annotations are defined in file language\ast\Ast.scala
:
Keywords ▴
The list of Flix keywords is available from several locations :
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 fileca/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 |
... | ... |
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. |
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 ].
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:
Other than syntax, the two languages are very different:
a) the use of short keywords,
b) thex : T
syntax for type annotations,
c) theList[Int32]
syntax for type parameters, and
d)if
,match
, etc. as expressions.