Giter Site home page Giter Site logo

lctr / wysk Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 1.14 MB

A statically typed functional language with type inference, ad-hoc polymorphism, and an extensible operator syntax. Influenced by Rust, ML, and Haskell.

License: MIT License

Rust 99.94% Shell 0.06%
ad-hoc-polymorphism compiler custom-operators hindley-milner programming-language functional-programming

wysk's Introduction

Wysk

A statically typed, functional language inspired by Haskell, ML, and Rust. This language is effectively a rewrite and redesign of all the prior languages I've (incompletely) implemented, but with an emphasis on modular (and ideally non-monolithic) code.

The Wysk language aims to eventually branch away from its admittedly Haskell-heavy influence, and currently touts the following features (either complete or as goals):

  • algebraic data types
  • static type inference via Hindley-Milner
  • systematic overloading and polymorphism via type classes
  • a flexible module system
  • robust concurrency afforded by lazy semantics and a run-time system written purely in Rust
  • leveraging the low-level power of Rust with the high-level semantics of Haskell

I am still fairly inexperienced when it comes to compiler development, so it follows that this project -- and its documentation -- is very much a work in progress.

Additionally, this compiler aims to use as little dependencies as possible. The common exceptions to this are the lazy_static, serde and toml crates; aside from these two, the lack of external dependencies allows for a greater amount of flexibility and control over specific functions and implementations used within the compiler, as well as proving to be a wonderful exercise in learning how to truly appreciate what the Rust standard library has to offer. With that being said, additional dependencies will likely be added on an as-needed basis as the compiler itself matures -- but that'll have to wait until I get tired of handrolling my own Rust :).

[WIP] Examples

Hello world

The entry point to every program, the function main operates within IO. The actual return type of main is generally irrelevant, but must be contained within the IO type.

fn main :: IO ()
  = printLine "Hello world!"

Factorial

Wysk does not have traditional loops; instead it relies on recursion to achieve the same effect. With tail-call optimization, this generally allows for fearless recursion (assuming convergent tail recursion). This can be exploited along with case-like syntax at the function definition level, allowing for branches to be predicated upon from a function's top-most scope.

fn factorial :: Int -> Int
  | n if n < 2 = 1
  | n = n * factorial (n - 1)

Fibonacci

Functions may be matched on with either case or match expressions, where match expressions correspond to function in OCaml or \case in Haskell, i.e., are sugar for \x -> match x { ... }. Wysk additionally supports (nested) or-patterns, allowing for pattern matching to be written as concisely as necessary without repeated code.

fn fibs :: Int -> Int
  = match
  | (0 | 1) -> 1
  | n -> fibs (n - 1) + fibs (n - 2)

Some reading

The following may not necessarily be directly involved within the development of this compiler, but have proven nonetheless to be valuable sources of information.

wysk's People

Contributors

lctr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.