Code Monkey home page Code Monkey logo

jazz's Introduction

Jazz

Story

Jazz is a functional language that takes inspiration from Elixir and Haskell. I love writing Haskell, but for beginners, the category theory oriented type system is confusing1. Rather than monads, semigroupoids, etc, I will have a more standard approach to typeclasses, with classes like Collection, Orderable, etc.

Features

  • ADTs
  • Easy to understand syntax
  • Performant. Will generate LLVM IR in the future.
  • Strong, static typing
  • Incredible type inferrence
  • Immutable variables
  • First class functions
  • Pattern matching
  • Functions are curried by default
  • First class functions
  • Tuples

Examples

Hello World

Jazz
print! "Hello, world".
Javascript
console.log("Hello, world")

Currying and Partial Application

// Reference type signatures for built in functions
// (+) :: Num -> Num -> Num
// map :: (a -> b) -> [a] -> [b]

// These examples illustrate that functions are curried by default and support partial application. I will provide type signatures for these functions for reference, but they are not needed and infer correctly
add10 :: Integer -> Integer.
add10 = (+10).
add10List :: [Integer] -> [Integer].
add10List = map add10.
// Note that I don't have to write:
// add10List = \(xs) -> map add10 xs

nums = [1,2,3,4,5].
print! $ add10List nums.
// $ is an operator used to avoid parenthesis. Technically, it is a right associative, 0 precidence function application operator.
// Without the $, I would need to write `print! (add10List nums)`, because the parser thinks I mean (in Java syntax) `print!(add10List, nums)`.

Array operations

Jazz
myArr = [1, 2, 3, 4, 5].
evens = filter myArr \(i) -> mod(i, 2) == 0.
powersOf2 = map myArr \Num.pow(2, \0).
// Is the same as
powersOf2 = map myArr \(i) -> Num.pow(2, i).
Javascript
const myArr = [1, 2, 3, 4, 5]

let evens = []
for (let i in myArr) {
  if (i % 2 == 0) evens.push(i)
}

// Functional approach
let powersOf2 = myArr.map(i => Math.pow(2, i))

Functions

In Jazz, functions are pure by default and are declared with assignment to a lambda. Impure functions must be denoted with ! and can not be called from pure functions.

  • Multiline functions must use curly braces
  • Impure functions must end with a ! e.g:
    • println! = \(str) -> ...
Jazz
// Implicit types
isEven = \(i) -> mod(i, 2) == 0.
// Explicit types
isEven :: Integer -> Bool.
isEven = \(i) -> mod(i, 2) == 0.

// Multiline functions
greet! = \() -> {
  name = getLine!.
  println!("Hello, ${name}").
}.

greet2! = \(name) -> {
  println! "Hello, ${name}".
}.

// Pure greeting function that just returns the string
greet3 = \(name) -> {
  "Hello, ${name}".
}.
Javascript
function isEven(i) {
  return i % 2 == 0
}
// Or
const isEven = i => i % 2 == 0

Modules

Jazz
module Person::Organs::Heart {
  beat = # do stuff
}
Javascript
// In file "./Person/Organs/Heart.js"
export class Heart {
  function beat() {
    // Do stuff
  }
}

Footnotes

  1. A monad is just a monoid in the category of endofunctors, what's the problem? โ†ฉ

jazz's People

Contributors

un3qual avatar

Watchers

Ray Toal avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.