### Test Installation from Bundle (Windows Batch) Source: https://github.com/koka-lang/koka/blob/dev/util/README.md Test the installation process on Windows using the `install.bat` script to install a Koka bundle from a tarball. Replace placeholders with actual version and OS/architecture details. ```batch $ util/install.bat ./bundle/v/koka-v--.tar.gz ``` -------------------------------- ### Test Installation from Bundle (Shell) Source: https://github.com/koka-lang/koka/blob/dev/util/README.md Test the installation process by using the provided `install.sh` script to install a Koka bundle from a tarball. Replace placeholders with actual version and OS/architecture details. ```bash $ util/install.sh ./bundle/v/koka-v--.tar.gz ``` -------------------------------- ### Pull and Run Docker Image Source: https://github.com/koka-lang/koka/blob/dev/test/bench/readme-pldi40.txt.md Instructions to pull the specified Docker image and start an interactive session. This is the initial setup for running the benchmarks. ```bash docker pull daanx/pldi-perceus:1.0 ``` ```bash docker run -it daanx/pldi-perceus:1.0 ``` -------------------------------- ### Install Koka on Windows Source: https://github.com/koka-lang/koka/blob/dev/util/release.md Downloads and runs the Windows installer script. Custom prefixes can be specified. The installer may prompt for additional compiler and SDK installations. ```batch curl -sSL -o %tmp%\install-koka.bat https://github.com/koka-lang/koka/releases/download/v3.2.3/install.bat && %tmp%\install-koka.bat ``` ```batch curl -sSL -o %tmp%\install-koka.bat https://github.com/koka-lang/koka/releases/download/v3.2.3/install.bat && %tmp%\install-koka.bat --prefix=c:\programs\local ``` ```batch curl -sSL -o %tmp%\install-koka.bat https://github.com/koka-lang/koka/releases/download/v3.2.3/install.bat && %tmp%\install-koka.bat --uninstall ``` -------------------------------- ### Install Haskell Stack Source: https://github.com/koka-lang/koka/blob/dev/test/fip/README.md Downloads and installs the Haskell Stack build tool. ```bash curl -sSL https://get.haskell.stack.org | sh ``` -------------------------------- ### Install System Dependencies Source: https://github.com/koka-lang/koka/blob/dev/test/fip/README.md Installs essential packages for building Koka and its benchmarks on a Unix-like system. ```bash sudo apt update sudo apt ugrade sudo apt-get install -y --no-install-recommends ca-certificates sudo apt-get install -y --no-install-recommends libc-dev build-essential time bc sudo apt-get install -y --no-install-recommends tar cmake curl sudo apt-get install -y --no-install-recommends gcc clang ``` -------------------------------- ### Install vcpkg and PCRE Source: https://github.com/koka-lang/koka/blob/dev/readme.md Clones and bootstraps vcpkg, then installs the PCRE library. Koka automatically detects vcpkg if installed in the ~/vcpkg directory. ```sh ~$ git clone https://github.com/microsoft/vcpkg ~$ ./vcpkg/bootstrap-vcpkg.sh ~$ vcpkg/vcpkg install pcre ``` -------------------------------- ### Create Koka installer with minbuild Source: https://github.com/koka-lang/koka/blob/dev/readme.md Generates an install bundle from a Koka build created with minbuild.sh. ```sh ~/koka$ .koka/minbuild/koka -e util/bundle.kk -- --koka=.koka/minbuild/koka ``` -------------------------------- ### Build All Benchmarks Source: https://github.com/koka-lang/koka/blob/dev/test/fip/README.md Compiles all benchmarks. Use this command to start the benchmark process. ```bash test# ./bench.sh allb build ``` -------------------------------- ### Install Swift Compiler Source: https://github.com/koka-lang/koka/blob/dev/test/bench/README.md Installs the Swift compiler by unpacking the release and copying it to the expected directory. This is a prerequisite for running Swift-based benchmarks. ```bash > tar -xzf swift-5.5-RELEASE-ubuntu20.04.tar.gz > cd swift-5.5-RELEASE-ubuntu20.04/usr > sudo mkdir /opt/swift > sudo cp -r * /opt/swift ``` -------------------------------- ### Install Koka Bundle on Windows Source: https://github.com/koka-lang/koka/blob/dev/readme.md Install the generated Koka bundle using the provided batch script. ```bat $ util/install.bat ``` -------------------------------- ### Create Koka installer with Cabal Source: https://github.com/koka-lang/koka/blob/dev/readme.md Builds an installer package for Koka using Cabal. ```sh ~/koka$ cabal new-run koka -- -e util/bundle ``` -------------------------------- ### Install Koka Bundle on Unix/macOS Source: https://github.com/koka-lang/koka/blob/dev/readme.md Install the generated Koka bundle using the provided installation script. ```sh $ util/install.sh bundle//koka-- ``` -------------------------------- ### Verify Koka Installation Source: https://github.com/koka-lang/koka/blob/dev/readme.md After installation, check the Koka version to confirm successful setup. ```sh $ koka --version ``` -------------------------------- ### Install GHC and Cabal on FreeBSD Source: https://github.com/koka-lang/koka/blob/dev/readme.md Installs the necessary GHC and Cabal packages on FreeBSD using pkg. ```sh $ sudo pkg update $ sudo pkg install ghc hs-cabal-install # or: hs-haskell-platform ``` -------------------------------- ### Create Koka Install Bundle Source: https://github.com/koka-lang/koka/blob/dev/readme.md Build Koka without the --fast flag and then execute the bundle utility to generate a distributable archive. ```sh $ stack build $ stack exec koka -- -e util/bundle ``` -------------------------------- ### Install Koka on Linux/macOS Source: https://github.com/koka-lang/koka/blob/dev/util/release.md Installs Koka using a curl script. Specify a custom prefix to change the installation directory. ```bash curl -sSL https://github.com/koka-lang/koka/releases/download/v3.2.3/install.sh | sh ``` ```bash curl -sSL https://github.com/koka-lang/koka/releases/download/v3.2.3/install.sh | sh -s -- --prefix=~/.local ``` ```bash curl -sSL https://github.com/koka-lang/koka/releases/download/v3.2.3/install.sh | sh -s -- --uninstall ``` -------------------------------- ### Create Koka Installation Bundle with System GHC Source: https://github.com/koka-lang/koka/blob/dev/readme.md This command builds the Koka project using stack with the system GHC, and then executes the bundling utility. The `--system-ghc` flag is passed to both stack and the bundling utility. ```sh stack --system-ghc --skip-ghc-check exec koka -- -e util/bundle -- --system-ghc ``` -------------------------------- ### Install OCaml with Multicore and Effects Source: https://github.com/koka-lang/koka/blob/dev/test/bench/README.md Installs a specific version of OCaml with multicore and effect handler support, along with necessary libraries like dune and domainslib. This is required for certain benchmarks. ```bash > opam update > opam switch create 4.12.0+domains+effects --repositories=multicore=git+https://github.com/ocaml-multicore/multicore-opam.git,default > opam install dune domainslib ``` -------------------------------- ### Install Java 17 JDK Source: https://github.com/koka-lang/koka/blob/dev/test/bench/README.md Installs the Java SE 17 Hotspot compiler and sets it as the default. This is necessary for running Java-based benchmarks. ```bash > sudo apt update > sudo add-apt-repository ppa:linuxuprising/java > sudo apt-get -y install oracle-java17-installer oracle-java17-set-default > java --version java 17 2021-09-14 LTS Java(TM) SE Runtime Environment (build 17+35-LTS-2724) Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing) ``` -------------------------------- ### Install Koka VS Code Extension Source: https://github.com/koka-lang/koka/blob/dev/support/vscode/README.md Install the built Koka VS Code extension using the VS Code command line. ```bash code --install-extension language-koka-.vsix ``` -------------------------------- ### Build and Run Koka Playground Source: https://github.com/koka-lang/koka/blob/dev/web/playground/PLAYGROUND.md Builds the Koka Playground WASM, precompiles the standard library, and deploys assets. Then, starts the Vite development server. ```bash cd web/playground && npm install cd ../.. stack run koka -- -e util/playground # builds WASM, precompiles stdlib, deploys assets cd web/playground && npx vite --host ``` -------------------------------- ### Chained Function Calls with Dot Notation Source: https://github.com/koka-lang/koka/blob/dev/doc/rise4fun/guide.kk.md Demonstrates chaining multiple function calls using Koka's dot notation, which is syntactic sugar for function application. This example shows encoding a string, getting its length, and printing the result. ```koka function showit( s : string ) -> s.encode(3).length.println ``` -------------------------------- ### Install Koka Package on OpenSUSE Source: https://github.com/koka-lang/koka/blob/dev/util/packaging/readme.md If OpenSuse throws an error when trying to install a built package, try refreshing the repositories first. ```sh $ sudo zypper in -t package /data/koka-2.3.7-opensuse.rpm ``` ```sh $ sudo zypper ref -f ``` -------------------------------- ### Install GHC and Cabal on Debian/Ubuntu Source: https://github.com/koka-lang/koka/blob/dev/readme.md Installs the necessary GHC and Cabal packages on Debian-based systems. ```sh $ sudo apt update $ sudo apt install ghc cabal-install ``` -------------------------------- ### Install GHC WASM Source: https://github.com/koka-lang/koka/blob/dev/web/playground/PLAYGROUND.md Installs GHC WASM 9.12. Ensure you have the necessary prerequisites before running. ```bash FLAVOUR=9.12 sh <(curl -sL https://gitlab.haskell.org/ghc/ghc-wasm-meta/-/raw/master/bootstrap.sh) ``` -------------------------------- ### Build Koka VS Code Extension Source: https://github.com/koka-lang/koka/blob/dev/support/vscode/README.md Install dependencies and build the Koka VS Code extension. ```bash cd support/vscode/koka.language-koka npm install npm run build ``` -------------------------------- ### Install GHC and Cabal on macOS Source: https://github.com/koka-lang/koka/blob/dev/readme.md Installs the necessary GHC and Cabal packages on macOS using Homebrew. ```sh $ brew install pkg-config ghc cabal-install ``` -------------------------------- ### Run Koka Interactive Compiler Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/getstarted.kk.md Start the Koka interactive compiler by simply running the 'koka' command without any arguments. This opens a REPL for testing expressions. ```bash $ koka _ _ | | | | | | _ ___ | | _ __ _ | |/ / _ \| |/ / _' | welcome to the koka interactive compiler | ( (_) | ( (_| | version 2.3.1, Sep 21 2021, libc x64 (clang-cl) |_|\_\___/|_|\_\__,_| type :? for help, and :q to quit loading: std/core loading: std/core/types loading: std/core/hnd > ``` -------------------------------- ### Build Mimalloc Source: https://github.com/koka-lang/koka/blob/dev/test/fip/README.md Clones, builds, and installs the Mimalloc memory allocator. ```bash git clone https://github.com/microsoft/mimalloc -b v2.1.1 cd mimalloc mkdir -p out/release cd out/release cmake ../.. make sudo make install cd ~ ``` -------------------------------- ### Compile VS Code Extension Source: https://github.com/koka-lang/koka/blob/dev/util/README.md Navigate to the VS Code extension directory, install dependencies, and build the extension. This process includes packaging the extension for distribution. ```bash $ cd support/vscode/koka.language-koka $ npm install $ npm run build $ npm run package $ cd ../../.. ``` -------------------------------- ### Invalid Layout Example Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/spec.kk.md Shows an example of an illegal layout where indentation is less than the layout context or comments interfere. ```unchecked fun equal( x : int, y : int ) : io bool { print("calculate equality") result = if (x == y) then True // wrong: too little indentation /* wrong */ else False result } ``` -------------------------------- ### Install Koka Vim Plugin with vim-plug Source: https://github.com/koka-lang/koka/blob/dev/support/vim/README.md Add this line to your vimrc or init.vim to install the Koka plugin using vim-plug. After adding, run the :PlugInstall command. ```vimscript Plug 'https://github.com/koka-lang/koka', { 'rtp': 'support/vim' } ``` -------------------------------- ### Koka Effects Example Source: https://github.com/koka-lang/koka/blob/dev/web/playground/embed.html Demonstrates Koka's effect tracking in the type system using the 'console' effect for printing. ```koka fun greet(name : string) : console () println("Hello, " ++ name ++ "!") fun main() greet("World") greet("Koka") ``` -------------------------------- ### Create Release Bundle (Windows without CL) Source: https://github.com/koka-lang/koka/blob/dev/util/README.md On Windows, create a release bundle for Koka, specifically excluding CL compiled files. This is useful if you are using clang-cl or do not have MSVC installed. Ensure VCPKG_ROOT is set if needed. ```bash $ stack exec koka -- -e util/bundle.kk -- --nocl ``` -------------------------------- ### Struct to Type Conversion Example Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Shows the desugaring of a struct definition into an equivalent algebraic data type definition with a single constructor. ```koka struct tp { } ↦ type tp { Tp { } } ``` -------------------------------- ### Struct Copy Constructor Example Source: https://github.com/koka-lang/koka/blob/dev/doc/rise4fun/guide.kk.md Demonstrates the automatically generated `copy` function for structs, used to create a new instance with potentially modified fields. ```koka function main() { println( gaga.copy().age ) } struct person( age : int, name : string, realname : string = name ) val gaga = Person( 25, "Lady Gaga" ) //// function copy( p, age = p.age, name = p.name, rname = p.realname ) { return Person(age, name, rname) } ``` -------------------------------- ### Build Koka with System GHC on macOS M1 Source: https://github.com/koka-lang/koka/blob/dev/readme.md These commands clone the Koka repository, navigate into the directory, and build the project using stack, explicitly telling stack to use the system-installed GHC and skip the GHC version check. This is necessary on arm64 where stack cannot install GHC. ```sh git clone --recursive https://github.com/koka-lang/koka cd koka stack --system-ghc --skip-ghc-check build ``` ```sh stack --system-ghc --skip-ghc-check exec koka ``` -------------------------------- ### Use Catch Handler Example Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Demonstrates using the `catch` handler to handle an exception from `safe-divide`. If an error occurs, it prints a message and returns 42. ```koka fun catch-example() with catch( fn(msg){ println("error: " ++ msg); 42 } ) safe-divide(1,0) ``` -------------------------------- ### Surprising example with choice and state effects Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Illustrates the interaction between `choice` and `state` effects. The `surprising` function demonstrates how state changes can affect the outcome of choices. ```koka fun surprising() : > bool val p = choice() val i = get() set(i+1) if i>0 && p then xor() else False ``` -------------------------------- ### Pull and Run Docker Image Source: https://github.com/koka-lang/koka/blob/dev/test/bench/readme-icfp22.txt.md Commands to pull the specified Docker image and start an interactive session within it. This sets up the environment for running benchmarks. ```bash docker pull daanx/icfp22-reuse:1.3 ``` ```bash docker run -it daanx/icfp22-reuse:1.3 ``` -------------------------------- ### Example of fun operation in Koka Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Demonstrates using a 'fun' operation for a simple operation 'ask' within another function 'ask-const2'. This highlights that 'fun' operations behave like regular functions. ```koka fun ask-const2() : int with fun ask() 21 add-twice() ``` -------------------------------- ### Implicit Parameter Passing in Koka Source: https://github.com/koka-lang/koka/blob/dev/support/vscode/koka.language-koka/whatsnew.md Explains how implicit parameters in Koka can now be passed as regular arguments, removing the requirement for them to be named. Example shows passing `list/show` as an implicit parameter. ```koka `[1].println(list/show)` ``` -------------------------------- ### Load and Run Sample Programs in Koka Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/getstarted.kk.md Load sample programs from the 'samples' directory using the ':l' command in the interactive compiler. Use 'main()' to execute the loaded program. ```koka > :l samples/basic/fibonacci > main() ... The 10000th fibonacci number is 33644764876431783266621612005107543310302148460680063906564769974680081442166662368155595513633734025582065332680836159373734790483865268263040892463056431887354544369559827491606602099884183933864652731300088830269235673613135117579297437854413752130520504347701602264758318906527890855154366159582987279682987510631200575428783453215515103870818298969791613127856265033195487140214287532698187962046936097879900350962302291026368131493195275630227837628441540360584402572114334961180023091208287046088923962328835461505776583271252546093591128203925285393434620904245248929403901706233888991085841065183173360437470737908552631764325733993712871937587746897479926305837065742830161637408969178426378624212835258112820516370298089332099905707920064367426202389783111470054074998459250360633560933883831923386783056136435351892133279732908133732642652633989763922723407882928177953580570993691049175470808931841056146322338217465637321248226383092103297701648054726243842374862411453093812206564914032751086643394517512161526545361333111314042436854805106765843493523836959653428071768775328348234345557366719731392746273629108210679280784718035329131176778924659089938635459327894523777674406192240337638674004021330343297496902028328145933418826817683893072003634795623117103101291953169794607632737589253530772552375943788434504067715555779056450443016640119462580972216729758615026968443146952034614932291105970676243268515992834709891284706740862008587135016260312071903172086094081298321581077282076353186624611278245537208532365305775956430072517744315051539600905168603220349163222640885248852433158051534849622434848299380905070483482449327453732624567755879089187190803662058009594743150052402532709746995318770724376825907419939632265984147498193609285223945039707165443156421328157688908058783183404917434556270520223564846495196112460268313970975069382648706613264507665074611512677522748621598642530711298441182622661057163515069260029861704945425047491378115154139941550671256271197133252763631939606902895650288268608362241082050562430701794976171121233066073310059947366875 ``` -------------------------------- ### Build Benchmarks with CMake Source: https://github.com/koka-lang/koka/blob/dev/test/bench/README.md Builds the benchmark suite using CMake. Navigate to the benchmark directory, create a build folder, and then configure and build the project. ```bash > cd test/bench > mkdir build > cd build > cmake .. -DCMAKE_BUILD_TYPE=Release > cmake --build . ``` -------------------------------- ### Build and Run Specific Benchmark Source: https://github.com/koka-lang/koka/blob/dev/test/fip/README.md Navigates to the test directory and builds and runs the 'rbtree' benchmark. ```bash cd ~/koka/test/fip ./bench.sh rbtree build run ``` -------------------------------- ### Koka Type Inference Example Source: https://github.com/koka-lang/koka/blob/dev/web/playground/embed.html A read-only example showcasing Koka's type inference for list variables. ```koka // Type inference example val xs = [1, 2, 3] // xs : list val ys = xs.map(show) // ys : list ``` -------------------------------- ### Run Benchmarks by Language and Test with bench.kk Source: https://github.com/koka-lang/koka/blob/dev/test/bench/README.md Specifies a comma-separated list of languages and/or benchmarks to run using the `bench.kk` script. Use `--lang` for languages and `--test` for specific benchmarks. ```bash > koka -e ../bench -- --lang=koka,ocaml --test=rbtree,rbtree-ck ``` -------------------------------- ### List Available Samples in Koka REPL Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/getstarted.kk.md In the Koka interactive compiler, type ':l samples/' and press Tab twice to see available sample files and directories. ```koka > :l samples/ ``` -------------------------------- ### Build Koka from Source Source: https://github.com/koka-lang/koka/blob/dev/test/fip/README.md Clones the Koka repository, checks out a specific commit, and builds it using Stack. ```bash git clone --recursive https://github.com/koka-lang/koka -b dev-fbip cd koka git checkout 54a16a5 stack build --fast ``` -------------------------------- ### Hello World in Koka Source: https://github.com/koka-lang/koka/blob/dev/web/playground/embed.html A basic 'Hello, World!' program in Koka. Click 'Run' to compile and execute. ```koka fun main() println("Hello, Koka!") ``` -------------------------------- ### Build All Koka Packages Source: https://github.com/koka-lang/koka/blob/dev/util/packaging/readme.md Run this script from the repository root to automatically build every possible package. Supports x64 Linux. ```sh $ ./util/packaging/build.sh ``` -------------------------------- ### Build Koka from Source Source: https://github.com/koka-lang/koka/blob/dev/readme.md Clone the Koka repository and build the compiler using stack. Ensure submodules are initialized recursively. ```sh $ git clone --recursive https://github.com/koka-lang/koka $ cd koka $ stack update $ stack build --fast $ stack exec koka ``` -------------------------------- ### Qualified Koka Identifiers Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/spec.kk.md Examples of qualified identifiers in Koka, showing how module paths prefix identifiers. ```koka core/map std/core/(&) ``` -------------------------------- ### Valid Koka Identifiers Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/spec.kk.md Examples of valid identifiers in Koka, including lowercase for variables and uppercase for constructors. ```unchecked x concat1 visit-left is-nil x' Cons True ``` -------------------------------- ### Hello World with Explicit Braces Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md An alternative syntax for 'Hello world' using explicit curly braces, demonstrating Koka's brace elision. ```koka fun main() { println("Hello world!") // println output } ``` -------------------------------- ### Run Benchmarks with bench.kk Script Source: https://github.com/koka-lang/koka/blob/dev/test/bench/README.md Executes all benchmarks using the `bench.kk` script. This method also measures peak working set and calculates normalized scores. Run from the build directory. ```bash > koka -e ../bench ``` -------------------------------- ### Define an Emit Effect Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Defines an `:emit` effect for sending messages. This effect is used in subsequent examples to demonstrate handler abstraction. ```koka effect fun emit( msg : string ) : () ``` -------------------------------- ### Build Koka with minbuild.sh Source: https://github.com/koka-lang/koka/blob/dev/readme.md Builds the Koka compiler using the minimal build script, which directly invokes ghc. ```sh ~/koka$ ./util/minbuild.sh ``` -------------------------------- ### Koka Runnable Custom Function Source: https://github.com/koka-lang/koka/blob/dev/web/playground/embed.html An example of a runnable Koka function defined with 'fun example/'. This function demonstrates a mutable counter. ```koka fun example/counter() var count := 0 repeat(5) count := count + 1 println("Count: " ++ count.show) ``` -------------------------------- ### Run Benchmarks with Options Source: https://github.com/koka-lang/koka/blob/dev/test/fip/README.md Executes all benchmarks and displays performance scores. Use the -n option to specify the number of runs. ```bash test# ./bench allb build run -n=10 ``` -------------------------------- ### Emit Messages Example Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md A simple function that uses the `:emit` effect to send two string messages. This serves as a base for demonstrating handlers. ```koka fun ehello() : emit () emit("hello") emit("world") ``` -------------------------------- ### List Benchmark Sources Source: https://github.com/koka-lang/koka/blob/dev/test/bench/readme-pldi40.txt.md Command to list the source files for a specific benchmark language (e.g., 'java'). This helps in locating the benchmark implementations. ```bash /build/koka/test/bench/build# ls ../java ``` -------------------------------- ### Define a Type with Parameters in Koka Source: https://github.com/koka-lang/koka/blob/dev/doc/rise4fun/guide.kk.md Constructors can accept parameters. This example defines a `number` type that can be either `Infinity` or an `Integer` with an `int` value. ```koka type number { Infinity Integer( i : int ) } ``` -------------------------------- ### List Benchmark Sources Source: https://github.com/koka-lang/koka/blob/dev/test/bench/readme-icfp22.txt.md View the source files for benchmarks in a specific language directory. This command lists the CMakeLists.txt and individual benchmark files for the Java implementation. ```bash /build/koka/test/bench/build# ls ../java CMakeLists.txt binarytrees.java cfold.java deriv.java nqueens.java rbtree.java rbtreeck.java ``` -------------------------------- ### Define State Effect Operations Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Defines the basic 'get' and 'set' operations for a generic state effect. This forms the foundation for stateful computations. ```koka effect state fun get() : a fun set( x : a ) : () fun sumdown( sum : int = 0 ) : ,div> int val i = get() if i <= 0 then sum else set( i - 1 ) sumdown( sum + i ) ``` -------------------------------- ### Define function effect signatures Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/why.kk.md Examples of function signatures demonstrating various effect types like total, exception, divergence, console, and non-determinism. ```koka fun sqr : (int) -> total int // total: mathematical total function fun divide : (int,int) -> exn int // exn: may raise an exception (partial) fun turing : (tape) -> div int // div: may not terminate (diverge) fun print : (string) -> console () // console: may write to the console fun rand : () -> ndet int // ndet: non-deterministic ``` -------------------------------- ### Hello World Program in Koka Source: https://github.com/koka-lang/koka/blob/dev/doc/rise4fun/guide.kk.md A basic 'Hello world' program demonstrating the syntax for defining a main function and using the `println` function for output. Functions are declared using the `function` or `fun` keyword. ```koka function main() { println("Hello world!") // println output } ``` -------------------------------- ### Run All Benchmarks Source: https://github.com/koka-lang/koka/blob/dev/test/bench/readme-icfp22.txt.md Command to execute all benchmarks with normalization and a specified number of iterations. This is used to generate the paper's benchmark figures. ```bash /build/koka/test/bench/build# koka -e ../bench.kk -- --norm --iter=10 ``` -------------------------------- ### While Loop with Suspended Braces Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Demonstrates the 'while' loop using braces for suspended expressions, which may be evaluated zero or more times. This example counts down from 10. ```koka fun main() { print11() } //// fun print11() var i := 10 while { i >= 0 } println(i) i := i - 1 ``` -------------------------------- ### Build and Test Koka Source: https://github.com/koka-lang/koka/blob/dev/util/README.md Perform a fast build of the Koka project and then run the interpreter and test suite to ensure everything is working correctly. ```bash $ stack build --fast $ stack exec koka ... > :l samples/all > all/main() ... > :q $ stack test ``` -------------------------------- ### Compile and Run Koka Program Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/getstarted.kk.md Compile a Koka source file using the 'koka' command. The output shows the compilation process and the creation of an executable. ```bash $ koka samples/basic/caesar.kk compile: samples/basic/caesar.kk loading: std/core loading: std/core/types ... check : samples/basic/caesar linking: samples_basic_caesar created: .koka/v2.3.1/gcc-debug/samples_basic_caesar ``` ```bash $ .koka/v2.3.1/gcc-debug/samples_basic_caesar plain : Koka is a well-typed language encoded: Krnd lv d zhoo-wbshg odqjxdjh cracked: Koka is a well-typed language ``` -------------------------------- ### Choice effect for backtracking Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Defines a `choice` effect and a function `xor` that uses it to explore multiple possibilities. This is a fundamental example for implementing backtracking or probabilistic programming. ```koka effect ctl choice() : bool fun xor() : choice bool val p = choice() val q = choice() if p then !q else q ``` -------------------------------- ### VSCode Launch Configuration for Koka Source: https://github.com/koka-lang/koka/blob/dev/support/vscode/koka.language-koka/README.md Defines how to set up custom launch configurations in VSCode's launch.json file for running Koka programs. Specify the program path, name, optional function, program arguments, and compiler arguments. ```json { "type": "koka", "request": "launch", "program": "", // The path to the file you want to run "name": "", // The name as you want it to appear in the run configurations dropdown "functionName": "", // optional function name to run "programArgs": [], // optional arguments you want to give to the compiled program "compilerArgs": "" // optional arguments you want to give to the compiler (e.g. --verbose or -O2) } ``` -------------------------------- ### Trailing Lambda with for loop Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Use trailing lambdas to place anonymous functions after the function call for improved readability. This example prints numbers from 1 to 10. ```koka fun main() { print10() } //// fun print10() for(1,10) fn(i) println(i) ``` -------------------------------- ### State Modeling with Peek and Poke Effects Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Illustrates modeling state using 'peek' and 'poke' effects. The 'ppstate' handler uses 'mask' to manage a growing stack of peek handlers, preventing type inflation. ```koka effect val peek : a // get the state effect ctl poke( x : a ) : () fun ppstate( init : a, action : () -> ,poke|e> b ) : e b with val peek = init with ctl poke(x) mask with val peek = x resume(()) action() ``` -------------------------------- ### List Benchmark Files Source: https://github.com/koka-lang/koka/blob/dev/test/fip/README.md Lists the benchmark files available in the msort directory. ```bash test# ls src/msort msort-fip.kk msort-std.kk ``` -------------------------------- ### Koka Loop with Effect Unification Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md An example of a loop where the effects of the predicate and action are automatically unified by Koka to a common effect type that includes divergence, exceptions, and non-determinism. ```koka fun looptest() while { is-odd(srandom-int()) } throw("odd") ``` -------------------------------- ### Run Koka Benchmark Source: https://github.com/koka-lang/koka/blob/dev/test/bench/readme-icfp22.txt.md Execute Koka benchmarks with specified iterations and normalization. Ensure the Koka compiler is in your PATH. ```bash koka -e ../bench.kk -- --iter=10 --norm ``` -------------------------------- ### Nested Function Calls with 'with' Statement Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Shows a more concise way to write nested function calls using the 'with' statement, achieving the same result as the previous example. ```koka pub fun test-with1() with twice with twice println("hi") ``` -------------------------------- ### Koka `while` loop with effect unification Source: https://github.com/koka-lang/koka/blob/dev/doc/rise4fun/guide.kk.md Demonstrates the `while` function and how Koka unifies effects from the predicate and action. The example shows how effects like divergence (`div`) and exceptions (`exn`) are combined. ```koka function main() { looptest() } //// function looptest() { while { odd(randomInt()) } { error("") } } ``` -------------------------------- ### Set Command Line Options in Koka REPL Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/getstarted.kk.md Configure the interactive compiler using the ':set' command. Options like '--showtime' can be used to display execution times. ```koka > :set --showtime > :l samples/basic/rbtree.kk > main() ... 420000 info: elapsed: 4.104s, user: 4.046s, sys: 0.062s, rss: 231mb ``` -------------------------------- ### Compile Koka (Manual Process) Source: https://github.com/koka-lang/koka/blob/dev/util/README.md Manually build the Koka project using stack and verify that the interpreter is functional. This step is part of the older manual release process. ```bash $ stack build $ stack exec koka # check if interpreter works > :l samples/all > all/main() ... > :q ``` -------------------------------- ### Run Benchmarks with Iterations Source: https://github.com/koka-lang/koka/blob/dev/test/bench/README.md Runs each benchmark a specified number of times (`N`) and calculates the average execution time along with the error interval. Use the `-i` switch. ```bash > koka -e ../bench -i ``` -------------------------------- ### Define Specialized List Type in Koka Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Define a custom list type to reduce allocations due to boxing for performance-sensitive code. This example shows a specialized list for integers and booleans. ```koka type mylist MyCons{ head1: int; head2: bool; mytail: mylist } MyNil ``` -------------------------------- ### Function Call with Named Parameters Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Demonstrates calling the `replace-all` function using named parameters for clarity and flexibility, specifying `repl` and `pattern` explicitly. ```koka fun main() { println(world2()) } //// fun world2() "hi there".replace-all( repl="world", pattern="there" ) ``` -------------------------------- ### 'with finally' for Exception Handling Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md Uses the 'with finally' construct to ensure a cleanup action is executed when exiting a scope, even if an exception occurs. This example prints a message upon exiting. ```koka fun test-finally() with finally{ println("exiting..") } println("entering..") throw("oops") + 42 ``` -------------------------------- ### Anonymous Function without Arguments using Braces Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md For anonymous functions without arguments, the 'fn' keyword can be omitted, and braces can be used directly. This example uses 'repeat' to print 'hi' 10 times. ```koka fun main() { printhi10() } //// fun printhi10() repeat(10) println("hi") ``` -------------------------------- ### Run All Benchmarks Source: https://github.com/koka-lang/koka/blob/dev/test/fip/README.md Execute all available benchmarks multiple times to gather median runtimes and standard errors for paper figures. ```bash test# ./bench.sh allb run -n=10 ``` -------------------------------- ### Koka Generator Effect Example Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/index.kk.md Demonstrates a generator effect with a 'yield' operation and a function to traverse a list, yielding elements. The main function shows how to handle the yield operation by printing the yielded values. ```koka // A generator effect with one operation effect yield fun yield( x : a ) : () // Traverse a list and yield the elements fun traverse( xs : list ) : yield () match xs Cons(x,xx) -> { yield(x); traverse(xx) } Nil -> () fun main() : console () with fun yield(i : int) println("yielded " ++ i.show) [1,2,3].traverse ``` -------------------------------- ### Customizing Koka Syntax Highlighting in VSCode Source: https://github.com/koka-lang/koka/blob/dev/support/vscode/koka.language-koka/README.md Example of how to customize Koka syntax highlighting colors in VSCode's settings.json by defining rules for specific token scopes like types, constructors, numbers, and comments. ```json "editor.tokenColorCustomizations": { "textMateRules": [ { "scope": "koka.type", "settings": { "foreground": "#00B8B8" } }, { "scope": "koka.conid, koka.number", "settings": { "foreground": "#a6c2a3" } }, { "scope": "koka.comment.doc.pre", "settings": { "foreground": "#91ac91" } }, { "scope": "koka.id.decl.function", "settings": { "foreground": "#cac199" } }, ] } ``` -------------------------------- ### Hello World in Koka Source: https://github.com/koka-lang/koka/blob/dev/doc/spec/tour.kk.md The standard 'Hello world' program in Koka. Functions are declared using 'fun'. ```koka fun main() println("Hello world!") // println output ``` -------------------------------- ### Run All Benchmarks with CTest Source: https://github.com/koka-lang/koka/blob/dev/test/bench/README.md Executes all benchmarks using the CTest testing tool. This command should be run from the build directory. ```bash > ctest . ```