Coder Social home page Coder Social logo

montylang / monty Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 0.0 628 KB

Language from a parallel universe where Python is functional

Home Page: https://montylang.github.io/docs/

License: BSD 3-Clause "New" or "Revised" License

Haskell 90.20% Emacs Lisp 1.19% Python 8.61%
functional-language language monty

monty's People

Contributors

elimirks avatar wolfecub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

monty's Issues

Should we have for comprehension?

It's not all that common in functional style, but it's common for Python programmers. Generally, using map and bind to create new lists is more FP-idiomatic

Create a REPL

We should have a simple repl, that imports a file (not running the main IO), and you can evaluate any single-line expression - which gets automatically wrapped in a debug

Infer function types at compile time (or semantic-time currently)

To compile to LLVM or some other bytecode, we'll have to improve our inference.

For example:

def add(a, b):
  return (x): str(x) + "," + str(a + b)

x = add(3, 7)

y = x("hi")
# Generate def add(a: int, b: int) -> (str -> str):
z = x(3.14)
# Generate def add(a: int, b: int) -> (float -> str):

In the case where a function type cannot be inferred, it's considered a no-op.

e.g.

x = add(3,7)

This expression alone doesn't do anything, because the function returned by add and assigned to x is never used.

Speed up the parser

It's very slow right now :( We probably need to have a simple preparser for lexing

Wacky currying + inference bug

This works:

return apply(wrap(append("hi: ")), readInt())

But this doesn't:

return apply(wrap(append("Number is: ")), readInt())

IO Monad

Monty lives in pure functional land right now. We need an IO monad entry point!

The __main__ thunk function should be the entry point to the "real world"

Case / Match statement

We should support case / match statements, supporting the same pattern matching that our functions do

Fix how IO works

IO should work more like StateT. Functions should return functions that are only evaluated inside of main.

Support networking in IO monad

It should be a very fundamental networking API - higher level functionality (e.g. HTTP) should be entirely implemented in Monty itself

Pass

We need to implement a pass keyword, similar to undefined in Haskell

Improvements to unwrap syntax

Unwrap should support assignments, and allow non-binding non-terminal expressions.

The assignments should behave similar to how they work imperatively

List of premature optimizations

Pass small ADTs by value

We can probably be clever with allocations for ADTs with few parameters. As in, pass them by value rather than allocate memory for all of them. A Maybe or Either type takes up a trivial amount more memory than whatever it contains, so it's probably worth just copying it instead of returning a reference or passing a reference to a function.

If all elements in an ADT only have 1 data slot, pass them by value instead of reference

If a closure environment doesn't contain non root references, make it a function

In version 1 of the compiler we're just making everything a closure, which is a bit pointless for functions that only have root level references

Try to store lists contiguously

The V1 allocator will be pretty dumb with lists, slotting them wherever possible. To utilize the cache better, we should try to store lists in contiguous memory.

Extending onto this, if you map over a list, it can trivially be given a contiguous memory block

Cache compiled library code

Instead of recompiling the entire stdlib for every program, cache the compiled libraries

Use TrieMap to prune redundant expressions and function definitions

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.