GithubHelp home page GithubHelp logo

l-applin / jim Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 141 KB

Programming langage project to have fun explorating different concept related to type system and functional programming

License: Apache License 2.0

Java 100.00%

jim's Introduction

Jim (working title)

Programming langage project to have fun exploring different concept related to type system and functional programming. Compiled to JVM Bytecode.

Everything subject to change.

Inspiration

  • Haskell type system,
  • Kotlin/Haskell syntax
  • Various Rust ideas
  • Java (semantics, ecosystem)

Development milestones

  • hello world
  • local variables
  • math expressions
  • all control flow:
    • for
    • if
    • case
  • bool expressions
  • function call
  • type definition
    • type alise
    • struct types
    • sum types
  • type checking.......
    • type infer
  • constant folding
  • imports/includes
  • type class and implementation
  • self-hosted??????
  • debug infos?
  • maven compiler plugin
  • compiler executable

... and much more

Known todos

  • Fix operator precedence
  • wide instructions (constant pool / local variables)

Examples

Working Hello World! in src/test/resources/Simple.jim:

  • run the test src/test/java/ca/applin/jim/compiler/CompilerTest.java which will try to compile src/test/resources/Simple.jim
  • It should have create target/generated-test-sources/classes/jim/Simple.class
  • you can run this class file simple by (from root):
cd target/generated-test-sources/classes
java jim.Simple

requirements

java 19: Preview features are enabled with maven in the pom

jib: You can clone the jib repository and mvn clean install so that the lib is available in you rlocal maven repository.

Language Features

  • Runs on the JVM, garbage collected and all.

  • Core support for functional types:

String -> Int
[A] -> Int
(A, B) -> Pair A B
(A -> B, Maybe A) -> Maybe B
(A -> Maybe B, Maybe A) -> Maybe B
  • Functions clearly show what their type is :
count_numbers :: String -> Int = str -> {
  total: Int = 0; 
  for str {
    if is_numeric(it) total++;
  }
  return total;
}
  • Type classes (instead of interface):
Maybe A :: Type = Just A | Nothing ;

Functor F :: Class {
  fmap :: (A -> B, F A) -> F B ;
}

Maybe A :: Implementation Functor A {
   fmap :: (A -> B, Maybe A) -> Maybe B = 
   (f, ma) -> case ma {
        Just a -> Just(f(a));
        Nothing -> Nothing();
   }
}

maybeStr := Just("Hello, World!);
println(fmap(str -> str.length, maybeStr));
>>> Just(13)
  • Algebraic data types:
// Sum type:
Either A B :: Type = Left A | Right B ; 

// product type (struct):
Pair   A B :: Type = { 
    left: A;
    right: B;
}

Simple_Pair A B :: Type = (A, B) ;

pair   := Pair(left="Oh my!", right=69) // `pair` variable is infered as type 'Pair String Int'
either := Left("Hello!")                // `either` variable  is infered as 'Either String _', not enough info to concluce the type Either second type parameter
simp   := ("Some tuple", 42)            // `simp` variable inferred as type '(String, Int)'

either2: Either String Int      = Left("Hello!")          // now we have wnough info to know that either 2 is of type 'Either String Int'
simp2:   Simple_Pair String Int = ("some other tuple, 69) // explicit, type is known to be 'Simple_Pair String Int'
  • Recursive Types:
Lisp_List A :: Type = Nil | Cons A (List A)

##TODOs

  • null value??
  • Macro? Rust macros are cool...
  • Code block?
  • Concurrency...

jim's People

Contributors

l-applin 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.