An experimental functional programming language with dependent types, inspired by Swift and Idris.

Overview

Kara

An experimental functional programming language with dependent types, inspired by Swift and Idris.

Motivation

Development of Kara is motivated by:

  1. Strong type safety. Kara relies on dependent types to eliminate bugs at compile time that can't be caught by mainstream languages.
  2. Familiar syntax. Kara's syntax should be familiar to everyone experienced with C language family, including Rust, Swift, TypeScript etc.
  3. Portability. Kara is developed with support for all major platforms in mind. We want Kara apps to be usable in the browser, as a system programming language, and potentially even in embedded settings, like Arduino, kernel extensions, audio DSP plugins etc.
  4. Performance. Where it's possible to compile Kara to native binary code, we want it to be as performant as Swift, but ideally it should as fast as Rust, Zig, or C/C++.
  5. Language Minimalism. Kara shouldn't ever become a huge language. Whatever can be implemented as a library should be implemented as a library instead of adding a new feature to the language, as long as it doesn't conflict with the rest of the goals.
  6. Distribution Minimalism and Economic Accessibility. A barebone distribution of Kara ready for basic development shouldn't take more than a hundred megabytes when installed as a native binary. Our users shouldn't need a ton of free storage, expensive hardware, and fiber broadband to get started. Additionally, Kara's toolchain should be available and working directly in a browser playground without a need to compile on cloud servers.

What's a dependent type?

With dependent types one could prevent out-of-bounds errors at compile time. For example, this code in Kara tries to access array elements that don't exist, but it won't type check:

let a1 = [1,2,3]
a1[3] // type error, out of bounds
let a2 = [4,5,6]
(a1 ++ a2)[6] // type error, OOB

This is achieved by encoding length of a collection in its type. Here [1, 2, 3] has type Vector , which requires its subscript arguments to be less than vector's length. These constraints are checked at compile time, but work even for vector length computed at run time. Vector length is propagated to new vectors created at run time thanks to the generic vector concatenation operator ++. Its type signature looks like this:

(++): <Element, Length1, Length2>(
  Vector<Element, Length1>, 
  Vector<Element, Length2>
) -> Vector<Element, Length1 + Length2>

Here Element, Length1, and Length2 are implicit generic arguments that refer to vector's element type and lengths of vectors.

The concept of dependent types allows us to use expressions in generic arguments of other types, like in Vector above. Here type of a vector depends on a value of its length. This allows us to check not only OOB for simple one-dimensional collections, but also matrix/tensor operations, pointers etc.

One other interesting application of dependent types are implementations of state machines where illegal state transitions don't type check. While this is something that's possible in Swift with phantom types, we want it to feel much more natural in Kara with its type system.

Current status

Example code from the previous section will not currently compile, or even type-check, although fixing this is the primary goal right now. Kara is at a very early stage and is not available for general or limited use at this moment. The project currently contains only a basic parser, type checker, interpreter, and JavaScript codegen. Documentation is sparse and most of the features are still in flux. Pre-release versions are currently only tagged for a purpose of some future retrospective.

Star and watch the repository if you're interested in imminent updates.

Contributing

If you'd like to contribute, please make sure you have a general understanding of Idris and ideally have read at least foundational parts of Type-Driven Development with Idris book, which inspire development of Kara. This is not a hard requirement for working on the Kara compiler, but it would be very helpful for all contributors to be on the same page with the general approach to designing the language.

Code of Conduct

This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].

License

Kara is available under the Apache 2.0 license. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the LICENSE file for more info.

You might also like...
A fancy collection style view controller that was inspired by this Profile Card mockup
A fancy collection style view controller that was inspired by this Profile Card mockup

JFCardSelectionViewController A fancy collection style view controller that was inspired by this Profile Card mockup: https://dribbble.com/shots/14584

React Native utility library around image and video files for getting metadata like MIME type, timestamp, duration, and dimensions. Works on iOS and Android using Java and Obj-C, instead of Node 🚀.

Qeepsake React Native File Utils Extracts information from image and video files including MIME type, duration (video), dimensions, and timestamp. The

LinkedLog is a Xcode plugin that includes a Xcode PCH header file template that adds the macros `LLog` and `LLogF` and parses their output to link from the console to the corresponding file and line.
LinkedLog is a Xcode plugin that includes a Xcode PCH header file template that adds the macros `LLog` and `LLogF` and parses their output to link from the console to the corresponding file and line.

LinkedLog Xcode Plugin LinkedLog is a Xcode plugin that includes a Xcode PCH file template that adds the macros LLog and LLogF. The LLog macro will wo

KnockToReact is an iOS library written in Swift and Objective-C that brings an exclusive feature to interact with users just by receiving and recognizing "knocks" in the device.

KnockToReact is an iOS library written in Swift and Objective-C that brings an exclusive feature to interact with users just by receiving and recognizing "knocks" in the device.

XCSnippetsApp - macOS application to explore code snippets from the Swift and iOS community, view and edit the snippets before adding them conveniently to Xcode
XCSnippetsApp - macOS application to explore code snippets from the Swift and iOS community, view and edit the snippets before adding them conveniently to Xcode

XCSnippetsApp macOS application to explore code snippets from the Swift and iOS community, view and edit the snippets before adding them conveniently

A Swift package that provides convenient Lorem Ipsum text, images, colors and other placeholders for rapidly prototyping, building and testing your iOS applications.
A Swift package that provides convenient Lorem Ipsum text, images, colors and other placeholders for rapidly prototyping, building and testing your iOS applications.

Lorem Introducing Lorem, a placeholder generator library for iOS to help you rapidly prototype, build and test your iOS applications. By leveraging Sw

AuroraEditor is a IDE built by the community, for the community, and written in Swift for the best native performance and feel for macOS.
AuroraEditor is a IDE built by the community, for the community, and written in Swift for the best native performance and feel for macOS.

AuroraEditor AuroraEditor is a IDE built by the community, for the community, and written in Swift for the best native performance and feel for macOS.

A Swift package for encoding and decoding Swift Symbol Graph files.
A Swift package for encoding and decoding Swift Symbol Graph files.

SymbolKit The specification and reference model for the Symbol Graph File Format. A Symbol Graph models a module, also known in various programming la

WebDomHandling - A Swift Package for handling JavaScript code between WebKit and Swift implemented by WebKit

WebDomHandling A Swift Package for handling JavaScript code between WebKit and S

Releases(0.2.0)
  • 0.2.0(Nov 16, 2021)

    Four major new features are supported in the parser, the type checker, and the interpreter (but not in JS codegen yet) in this release:

    • Static type members (functions and let bindings) with the static keyword.
    • Basic enums without associated values.
    • Leading dot notation, inspired by Swift. This allows omitting base type identifier in static member access and enum case expressions, where it can be inferred, like here:
    struct Int32 { static let max: Int32 = 2147483647 }
    func f(condition: Bool, x: Int32, y: Int32) {
      if condition { x } else { y }
    }
    

    With the declaration above, in an expression f(true, .max, 0) the second argument .max is inferred to be of type Int32.

    • switch expressions:
    enum E {
      case a
      case b
    }
    
    func stringify(x: E) {
      switch x {
      case .a:
        "a"
      case .b:
        "b"
      }
    }
    

    With the declaration above stringify(.a) and stringify(.b) are evaluated to "a" and "b" respectively. Missing cases in switch patterns are not type checked yet, thus the omission of case .b in switch may lead to runtime errors. This is a temporary limitation and will be resolved in a future version.

    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Oct 28, 2021)

    This release introduces two new features:

    • Struct literals, similar to struct literals in Rust and initializers in Swift. That is, an expression S [a: 0, b: 42, c: false] will create a value of type S with three fields that contain corresponding values. This assumes that struct S declaration with its fields is available in scope. The order of fields within square brackets is not taken into account, which makes it more convenient to create struct values with large number of fields. This means that S [c: false, b: 42, a: 0] is the same as the previous struct literal expression. Compare this to the enforced order of arguments passed to initializers in Swift.
    • Basic compile-time evaluation of type expressions is now available. This is the first step towards full support for dependent types. In the meantime it allows us to use type declarations that are equivalent to typealiases in Swift:
    let IntAlias: Type = Int
    let x: IntAlias = 42
    
    struct S {}
    let SAlias: Type = S
    let sValue = SAlias []
    
    Source code(tar.gz)
    Source code(zip)
  • 0.0.2(Oct 10, 2021)

    This preview release adds a basic type checker with type inference based on Typology. The type checker is integrated into the kara run CLI command.

    At this early stage diagnostics messages are very primitive and close to non-existent. Only a single error can be thrown when the checker pass fails, the pass does not proceed further with remaining declarations in that case.

    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(Oct 3, 2021)

Owner
null
Sonic language: Heavily inspired by Swift, but compiles to C so you can use it anywhere.

Sonic Sonic programming language: Heavily inspired by Swift, but compiles to C so you can use it anywhere. Brought to you by Chris Hulbert and Andres

Sonic Language 27 Apr 8, 2022
Allows you to emulate an Android native library, and an experimental iOS emulation

unidbg Allows you to emulate an Android native library, and an experimental iOS emulation. This is an educational project to learn more about the ELF/

Banny 2.5k Dec 30, 2022
Easy-to-use segues in SwiftUI, allowing for presenting views using common UIKIt Segue types - push, modal and popover

Easy-to-use segues in SwiftUI, allowing for presenting views using common UIKIt Segue types - push, modal and popover

Gordan Glavaš 5 Apr 16, 2022
A Collection of PropertyWrappers to make custom Serialization of Swift Codable Types easy

CodableWrappers Simplified Serialization with Property Wrappers Move your Codable and (En/De)coder customization to annotations! struct YourType: Coda

null 393 Jan 5, 2023
Swift Programming Basics - Collections, Variables & Constants

Dicee What I learned in this module How to clone an existing Xcode project from GitHub. Create an app with behaviour and functionality. Create links b

null 0 Jan 9, 2022
IMBeeHive is a kind of modular programming method

概述 IMBeeHive是用于iOS的App模块化编程的框架实现方案,本项目主要借鉴了阿里巴巴BeeHive,在此基础上通过逆向了一些大厂的APP使得功能更加强大完善。同时现在也在寻找一起开发这个框架的开发者,如果您对此感兴趣,请联系我的微信:alvinkk01. 背景 随着公司业务的不断发展,项目

null 6 Dec 14, 2021
Ulangi is a language flashcards app with spaced repetition system and more.

Ulangi Open-source language learning tools Introduction Ulangi makes it easy for you to manage and create flash cards to learn languages. It comes wit

Ulangi 384 Jan 3, 2023
The most powerful Event-Driven Observer Pattern solution the Swift language has ever seen!

Event-Driven Swift Decoupling of discrete units of code contributes massively to the long-term maintainability of your project(s). While Observer Patt

Flowduino 4 Nov 14, 2022
Kotlin Multiplatform sample with SwiftUI and Compose (Desktop and Android) clients. Heavily inspired by Wordle game.

WordMasterKMP Kotlin Multiplatform sample heavily inspired by Wordle game and also Word Master and wordle-solver samples. The main game logic/state is

John O'Reilly 56 Oct 4, 2022
Open source Clips-inspired app.

AlohaGIF Website Funny moments? Want to share it as a GIF, but you are worried that you will lose speech from video? Aloha will scan sound and attach

Mike Pyrka 61 Sep 16, 2022