Malgo Lang Malgo Save

A statically typed functional programming language.

Project README

malgo

Malgo CI

A statically typed functional programming language.

Requirement

Installation

Installing LLVM

Homebrew

$ brew install llvm-hs/llvm/llvm-12

Debian/Ubuntu

$ apt-get install llvm-9-dev

Installing Malgo

$ git clone https://github.com/malgo-lang/malgo
$ cd malgo
$ stack install
$ ./scripts/install_malgo_internal.sh

Usage

$ ./scripts/compile.sh examples/malgo/Hello.mlg
$ ./Hello
Hello, world

Examples

Hello, world

module Hello = {
  module {..} = import Builtin;
  module {..} = import Prelude;

  main = {
    putStrLn "Hello, world!"
  };
}

Fibonacci number

module Fib = {
  module {..} = import Builtin;
  module {..} = import Prelude;

  infix 4 (<=);
  (<=) = { x y -> leInt32 x y };

  infixl 6 (+);
  (+) = { x y -> addInt32 x y };

  infixl 6 (-);
  (-) = { x y -> subInt32 x y };

  fib = { n ->
    if (n <= 1)
      { 1 }
      { fib (n - 1) + fib (n - 2) }
  };

  main = {
    fib 5 |> toStringInt32 |> putStrLn
  };
}

List operations

module List = {
  module {..} = import Builtin;
  module {..} = import Prelude;

  infix 4 (<=);
  (<=) : Int32 -> Int32 -> Bool;
  (<=) = {x y -> leInt32 x y};

  infixl 6 (+);
  (+) : Int32 -> Int32 -> Int32;
  (+) = {x y -> addInt32 x y};

  infixl 6 (-);
  (-) : Int32 -> Int32 -> Int32;
  (-) = {x y -> subInt32 x y};

  map : (a -> b) -> List a -> List b;
  map = { _ Nil -> Nil
        | f (Cons x xs) -> Cons (f x) (map f xs)
        };

  sum : List Int32 -> Int32;
  sum = { Nil -> 0
        | Cons x xs -> x + sum xs
        };

  -- [0 .. n]
  below : Int32 -> List Int32;
  below = { n ->
    if (n <= 0)
       { [0] }
       { Cons n (below (n - 1)) }
  };

  main = {
      sum (map (addInt32 1) (below 10))
        |> toStringInt32
        |> putStrLn
  };
}

Lisp interpreter

https://github.com/malgo-lang/minilisp

TODO

Malgo タスクリスト - 星にゃーんのScrapbox

Compilation issue on macOS

In my case, stack build says:

llvm-hs> error: dyld[89679]: Library not loaded: @rpath/libc++abi.1.dylib
llvm-hs>   Referenced from: /usr/local/Cellar/llvm-12/12_2/lib/llvm-12/lib/libc++.1.0.dylib
llvm-hs>   Reason: tried: '/usr/local/lib/libc++abi.1.dylib' (no such file), '/usr/lib/libc++abi.1.dylib' (no such file)

I don't know exactly what caused this. However, I was able to solve it with ln -s /usr/local/lib/libc++abi.1.dylib /usr/local/Cellar/llvm-12/12/12_2/lib/llvm-12/lib/lib/libc++.1.0.dylib.

How to Test

# full test (parallel)
cabal test --test-show-details=streaming
# full test (serial)
cabal test --test-show-details=streaming --test-options='-j1'
# usual case (all optimization enabled) only
cabal test --test-show-details=streaming --test-options='--match "usual"'
# no all optimization case only
cabal test --test-show-details=streaming --test-options='--match "nono"'
# no lambda-lift optimization case only
cabal test --test-show-details=streaming --test-options='--match "nolift"'
# no other optimization case only
cabal test --test-show-details=streaming --test-options='--match "noopt"'

cabal exec malgo 
Open Source Agenda is not affiliated with "Malgo Lang Malgo" Project. README Source: malgo-lang/malgo
Stars
40
Open Issues
3
Last Commit
1 week ago
Repository
License

Open Source Agenda Badge

Open Source Agenda Rating