apple: Apple array language compiler

[ agpl, array, language, library, program ] [ Propose Tags ] [ Report a vulnerability ]

Compiler for a typed, APL-inspired array language.


[Skip to Readme]

library apple

library apple:as

Modules

[Index] [Quick Jump]

  • H

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0
Change log CHANGELOG.md
Dependencies apple, array, base (>=4.17 && <5), bytestring, composition-prelude (>=1.1.0.1), containers (>=0.6.0.1), criterion, deepseq, directory, dom-lt, extra (>=1.7.4), filepath, haskeline, libffi, microlens, microlens-mtl (>=0.1.8.0), mtl (>=2.2.2), optparse-applicative (>=0.14.0.0), prettyprinter (>=1.7.0), process, QuickCheck, split (>=0.2.0.0), temporary, text, transformers, unix [details]
License AGPL-3.0-only
Copyright Copyright: (c) 2022 Vanessa McHale
Author Vanessa McHale
Maintainer vamchale@gmail.com
Category Language, Array
Source repo head: git clone https://github.com/vmchale/apple
Uploaded by vmchale at 2024-09-10T18:36:13Z
Distributions
Executables arepl, writeo, atc
Downloads 77 total (14 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for apple-0.3.0.0

[back to package description]

Apple Array System

Some cases are not implemented. This is provided as an artefact.

See Apple by Example for a demonstration of capabilities.

The compiler will bail out with arcane error messages rather than produce an incorrect result, except that the Python/R extension modules do not enforce type safety and thus may mysteriously segfault or produce unpredictable corrupt results.

Spilling (during register allocation) is not implemented for Arm. Also floating-point registers aren't spilled on x86.

Compiler-As-a-Library

Rather than an environment-based interpreter or a compiler invoked on the command line and generating object files, one calls a library function which returns assembly or machine code from a source string.

Thus the same implementation can be used interpreted, compiled, or called from another language.

 > [((+)/x)%ℝ(:x)]\`7 (frange 1 10 10)
Arr (4) [4.0, 5.0, 6.0, 7.0]
>>> import apple
>>> import numpy as np
>>> sliding_mean=apple.jit('([((+)/x)%(ℝ(:x))]\`7)')
>>> apple.f(sliding_mean,np.arange(0,10,dtype=np.float64))
array([3., 4., 5., 6.])
> source("R/apple.R")
> sliding_mean<-jit("([((+)/x)%ℝ(:x)]\\`7)")
> run(sliding_mean,seq(0,10,1.0))
[1] 3 4 5 6 7

The JIT'ed moving average in Apple happens to be faster than the rolling mean from the zoo package.

Dimension As a Functor

This is based on J (and APL?). Looping is replaced by functoriality (rerank).

To supply a zero-cells (scalars) as the first argument to (cons) and 1-cells as the second:

(⊲)`{0,1}

We can further specify that the cells should be selected along some axis, e.g. to get vector-matrix multiplication:

λA.λx.
{
  dot ⇐ [(+)/((*)`x y)];
  (dot x)`{1∘[2]} (A::Arr (i`Cons`j`Cons`Nil) float)
}

The 2 means "iterate over the second axis" i.e. columns.

Installation

Use ghcup to install cabal and GHC. Then:

make install

to install arepl (the REPL).

Run

make
sudo make install-lib

To install the shared library.

Python

To install the Python module:

make install-py

R

Install libappler.so on your system like so:

make -C Rc
sudo make install-r

Then:

source("R/apple.R")

to access the functions.

Documentation

Type \l in the REPL to show the reference card:

 > \l
Λ             scan                     √             sqrt
⋉             max                      ⋊             min
⍳             integer range            ⌊             floor
ℯ             exp                      ⨳ {m,n}       convolve
\~            successive application   \`n           dyadic infix
_.            log                      'n            map
`             zip                      `{i,j∘[k,l]}  rank
𝒻             range (real)             𝜋             pi
_             negate                   :             size
𝓉             dimension                }.?           last
->n           select                   **            power
gen.          generate                 𝓕             fibonacci
re:           repeat                   }.            typesafe last
⊲             cons                     ⊳             snoc
^:            iterate                  %.            matmul
⊗             outer product            |:            transpose
{.?           head                     {.            typesafe head
}.?           last                     }:            typesafe init
⟨z,w⟩         array literal            ?p,.e1,.e2    conditional
...

Enter :help in REPL:

 > :help
:help, :h                    Show this help
:ty            <expression>  Display the type of an expression
...