Code Monkey home page Code Monkey logo

lang's Introduction

Languate

Yet another programming language.

Languate aims to be a simple, functional programming language, highly inspired by Haskell; but with a more concise syntax. Once it will be finished, tooling will be included from the first run, so that documentation generation, testing, ... is included from the very start.

It tries to be haskell without a few syntactic quirks.

Code examples

map (1+) [1,2,3]
[1,2,3].map(1+)

-- docstring for function, the compiler automatically generates the docs; parsed in **markdown**
> myFun 0 1 2   = 3     -- example embedded in the source code, acts as testcase (error if incorrect)
~ myFun with zero: myFun 0  = (+)       -- laws, checked by compiler; included in docs
myFun   : Int -> Int -> Int
0 a b   = a + b
x a b   = x*a + b

--- multiline
comment
with ---

--## Literate programming features for docs

Getting started

Install the Haskell platform (ghc+cabal) and mtl.

sudo apt-get install ghc cabal-install
cabal update
cabal install mtl

Clone the repo and install all

git clone [email protected]:pietervdvn/Lang.git
cd Lang
./installAll

Start the interpreter:

cd Interpreter
ghci Languate/MaintenanceAccess/TestInterpreter.hs 
-- You are now into an interactive haskell session
-- type "i" to evaluate a languate expression
i "True && True"

The result you get is a Value. It'll give you the type of the value, and which what contstructor it was built. (e.g. False is ADT: 0 <([pietervdvn:Data:Data.Bool.Bool],[])> [], True is ADT: 1 <([pietervdvn:Data:Data.Bool.Bool],[])> [], a list Elem True Empty is ADT: 1 <([(a0 -> (a1 -> [a]))],[])> [ADT: 1 <([pietervdvn:Data:Data.Bool.Bool],[])> [],ADT: 0 <([[a]],[])> []])

Try out boolean operators:

True && False
!False

Lists:

Elem True (Elem False Empty)
map (!) (Elem True (Elem False Empty))

If you want to use the BNF-lib to parse another languate, see the readme in bnf which contains a complete tutorial.

Repo structure

Workspace

Contains actual languate code!

StdDef

Some usefull functions, which where missing in the prelude.

Graphs

Some basic graph algorithms

Consumer

A lightweight lib wich contains one (monstrous) monad which combines lots of things. Is used in the regex and bnf parsing libs.

Regex

A regex parsing/interpreting lib. Used withing the bnf-lib.

BNF

A bnf lib to load, parse and 'execute' bnf-files. See the readme in the bnf-dir for a tutorial.

Parser

Converts Strings into Languate.AST-data. Where the syntax of the language is defined (see bnf) and where unclear error messages live where parse errors without explanation live.

Best help in case of parse error: take the bnf files and have a look where somehwere around it says it doesn't parse.

Loader

The loader is responsible for reading the manifest and reading all the needed modules from file. This cluster is then passed to the semantic analysis.

Semantic Analysis

The next step in the compiler pipeline, where typechecking happens and unclear error messages live.

Interpreter

A simple program which executes 'compiled' programs.

BinArch

Binary archive, which keeps all versions.

Selling points

  • Haskell-like syntax (but cleaned up a little)
  • Type Directed name resolution (ad hoc overloading, like in most OOP-languages)
  • Type interference
  • Laws, examples

lang's People

Contributors

iasoon avatar pietervdvn avatar rien avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

rien

lang's Issues

Better error messages

  • Friendlier output
  • parse world module rule should check if rule exists and is non-empty

Think about list/set syntax

What would be the best syntax for lists?

Patterns:

[a,b:as]  = a + b + f as
[a:b:as]  = a + b + f as

In combination with tuples

[(a,b):abs]
[a,b:c,d:abs]

Right hand side

a:as
[a:as]
[a,b:as]
[a:b:as]
[a,b] ++ as

In combination with tuples

[a,b:c,d:abs]

Improve pattern syntax for deconstructors

Implement guards

f : a -> a -> a
|(>=2) b  = b
_ b          = b

max : (a:Ord) -> a -> a
a |(<a)   = a   -- first arg= a; take this clause if second arg (<a)
_ b         = b

Guards should work both for booleans and Maybe ()

Implement deconstructor expressions

f : { Int --> v } -> v
((lookup 0) v)  = v
dict                  = ...

Type requirement syntax

In functions:

f  : a in Ord; b is Eq => a -> a -> b -> b -> Bool

In ADT defs:

data _ BalancedTree (a is Ord) = Top content:a left:(BalancedTree a) right:(BalancedTree a)
    | Nil

In class defs:

class Dict k v where:
    lookup : k -> Dict k v -> v

class Ord a => SortedSet a where:
    getMin : SortedSet a -> a


class SortedSet (a is Ord) where:
    getMin : SortedSet a -> a

class SortedSet a where a is Ord:
    getMin : SortedSet a -> a

Automatic Lensing

Automatically add lensing to records.

(Haskell syntax)

Suppose we have a record

data Game = {
    score :: Int,
    player :: Entity
    entities :: [Entity]
}

with Entity:

data Entity = {
    name :: String
    position :: Point
}

and Point:

data Point = {
    x :: Int,
    y :: Int
}

Each record would get automatic lensing. If you want the player entity to go up, you could write:

let game2 = game.player.position.y `modify` (+1)

or

(+=) = flip modify (+)
let game2 = game.player.position.y += 1

To do something for each element in a list, forEach would be a solution:

let game2 = game.entities `forEach` y *= 2

In some cases modify could be left out with automatic function renaming:

let game2 = game.score `modify` (\x -> function x 3)
--equivalent to
let game2 = game.score `function=` 3
let game2 = game.score `modify` double
--equivalent to
let game2 = game.score double!

Maybe operations could be chained together with do by providing a correct Monad instance:

let game2 = do
    game.player.position.y += 1
    game.player.position.x -= 3
    game.entities `update=` game

Rename 'class' to 'cat' and 'category'

  • Change from "class" to "cat" or "category"
  • Rename class-rulename to cat-rulename in bnf-files
  • Drop ":" on the end
  • Subtypes: allow ":" also (together with "in" and "is", already defined) (also see #49 )

Make "is" totally equivalent to ":" (in function declaration), make ("," equivalent to "&")

The : means that the type on the left is a subclass from the type on the right. E.g. in type declarations (a:Eq), category decls: cat Map k v : Set k.

For multiple subclassing, both "&" and "," should be possible: (a:Eq & Ord), (a:Eq, Ord);
cat Map k v : Set k, List b, cat X a b: Monad a & List b

  • Functions: declaration, lawDeclaration (do not touch law!)
  • Typedefs: optNamed, named, subclass
  • Types: reqSep (reuse this rule with a different name). ReqSep is the rule denoting "is subtype"
  • Types: add "disjunction" token, which can be , or &. Also see #54

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.