juvix icon indicating copy to clipboard operation
juvix copied to clipboard

A language for intent-centric and declarative decentralised applications

  • Juvix

#+begin_html CI status #+end_html

#+begin_html pages-build-deployment #+end_html

#+begin_html #+end_html

#+begin_html LICENSE #+end_html

#+begin_html Juvix Mascot #+end_html

** Description

Juvix is a research programming language created by [[https://heliax.dev/][Heliax]] as a first step toward creating more robust and reliable alternatives for formally verified smart contracts than existing languages. The Juvix language is constantly evolving, open-source, functional, and statically typed with special support for compiling [[https://anoma.network/blog/validity-predicates/][validity predicates]] to the =C= language, which can be deployed to various distributed ledgers including [[https://anoma.net/][Anoma]].

The Juvix language and related tools are documented in [[https://anoma.github.io/juvix/][the Juvix book]]. To write and test Juvix programs, you can use your favorite text editor and the =juvix= command line tool. However, we recommend using the =juvix-mode= in [[https://docs.juvix.org/tooling/emacs-mode.html][Emacs]] or the plugin in [[https://marketplace.visualstudio.com/items?itemName=heliax.juvix-mode][VSCode]].

** [[https://github.com/anoma/juvix/tree/main/examples/milestone][First examples of programs written in Juvix]]

The following links are clickable versions of their corresponding Juvix programs. The HTML output is generated by running =juvix html --recursive FileName.juvix=.

  • [[https://docs.juvix.org/examples/html/HelloWorld/HelloWorld.html][HelloWorld.juvix]]
  • [[https://docs.juvix.org/examples/html/Fibonacci/Fibonacci.html][Fibonacci.juvix]]
  • [[https://docs.juvix.org/examples/html/Hanoi/Hanoi.html][Hanoi.juvix]]
  • [[https://docs.juvix.org/examples/html/PascalsTriangle/PascalsTriangle.html][PascalsTriangle.juvix]]
  • [[https://docs.juvix.org/examples/html/Collatz/Collatz.html][Collatz.juvix]]
  • [[https://docs.juvix.org/examples/html/TicTacToe/CLI/CLI.TicTacToe.html][TicTacToe.juvix]]
  • [[https://docs.juvix.org/examples/html/ValidityPredicates/SimpleFungibleToken.html][SimpleFungibleToken.juvix]]

The [[https://anoma.github.io/juvix-stdlib/][Juvix standard library]] contains common functions that can be used in Juvix programs.

** Quick Start

*** Installing Juvix on MacOS

The easiest way to install Juvix on MacOS is by using [[https://brew.sh][Homebrew]].

To install the [[https://github.com/anoma/homebrew-juvix][homebrew-juvix tap]], run:

#+begin_src shell brew tap anoma/juvix #+end_src

To install Juvix, run:

#+begin_src shell brew install juvix #+end_src

After installing Juvix, you might want to try our doctor to check your system setup:

#+begin_src shell juvix doctor #+end_src

Helpful information on the shell can also be obtained by running:

#+begin_src shell brew info juvix #+end_src

*** Building Juvix from the sources

To install Juvix from the sources, you must download the [[https://github.com/anoma/juvix.git][Github repository]]. Then, the program can be installed with the following commands. We assume have [[https://haskellstack.org][Stack]] installed.

#+begin_src shell git clone --recursive https://github.com/anoma/juvix.git cd juvix stack install #+end_src

If the installation succeeds, you must be able to run the Juvix command from any location. To get the complete list of commands, please run =juvix --help=.

On MacOS, you can alternatively run the following command for Homebrew. The flag =--HEAD= used below is optional, mostly to build the latest version of Juvix in the =main= branch on Github.

#+begin_src shell brew install --build-from-source --HEAD juvix --verbose #+end_src

** The Hello World Example

In the following example a Juvix file is compiled to Wasm. Please check out the documentation [[https://anoma.github.io/juvix/getting-started/dependencies.html][Installing dependencies]] for instructions on how to setup your environment for compiling Juvix. You can also run =juvix doctor= to check your system setup.

#+begin_src shell -- HelloWorld.juvix module HelloWorld;

open import Stdlib.Prelude;

main : IO; main ≔ putStrLn "hello world!";

end; #+end_src

Then, run the following commands at the location folder of the file =HelloWorld.juvix=:

#+begin_src shell juvix compile HelloWorld.juvix wasmer HelloWorld.wasm #+end_src

You should see the output: =hello world!=

** The Juvix programming language

Juvix allows us to write programs with a high degree of assurance. The Juvix compiler runs several static analyses during the compilation phase to guarantee no runtime errors. Analyses permormed during this phase include scope, termination, arity, and type checkiqng. As a result, functional programs, especially validity predicates, can be written with greater confidence that they will be free of runtime errors.

Some of the language features in Juvix include:

  • unicode syntax
  • parametric polymorphism
  • inductive and parametric data types
  • higher-order functions
  • implicit arguments
  • holes in expressions
  • axioms for non-computable terms

Additionally, the foreign and compile blocks syntax enable developers to compile a program to different backends including the =C= language. The Juvix module system further permits splitting programs into several modules to build libraries which can be later documented by generating HTML files based on the codebase, see for example, [[https://anoma.github.io/juvix-stdlib/][the Juvix standard library's website]]. For futher details, please refer to [[https://anoma.github.io/juvix/][the Juvix book]] which includes our [[https://anoma.github.io/juvix/introduction/changelog.html][latest updates]].

** Coming soon

For the language:

  • lambda expressions
  • =let= expressions
  • tail call optimization
  • inference for mutually recursive functions
  • compilation to circuits
  • coverage checking (i.e. exhaustiveness and useless clauses)

For the compiler:

  • Init command
  • Better documentation tool: =juvix doc MyFile.juvix=

** Community

We would love to hear what you think of Juvix! Join us on [[https://discord.gg/vEQappb7wG][the Anoma Discord]].