Skip to content
bjpop edited this page Sep 14, 2010 · 29 revisions

Introduction to Berp

Berp is an implementation of Python 3. At the heart of Berp is a translator, which takes Python code as input and generates Haskell code as output. The Haskell code is then fed to a Haskell compiler (GHC) for compilation to machine code or interpretation as byte code.

Berp is written in Haskell.

As an example, consider this simple Python implementation of the factorial function:

def fac(n):
   result = 1
   while (n > 0):
      result = result * n
      n = n - 1
   return result

Given the above Python code as input, Berp will produce the following Haskell code as output:

do _s_fac <- var "fac"
   def _s_fac 1 none
      (\ [_s_n] ->
         do _s_result <- var "result"
            _s_result =: 1
            while
              (do _t_0 <- read _s_n
                  _t_0 > 0)
              (do _t_1 <- read _s_result
                  _t_2 <- read _s_n
                  _t_3 <- _t_1 * _t_2
                  _s_result =: _t_3
                  _t_4 <- read _s_n
                  _t_5 <- _t_4 - 1
                  _s_n =: _t_5)
            _t_6 <- read _s_result
            ret _t_6)

Even without knowing the details of the translation you ought to be able to see that there is a fairly strong correspondence between the input Python code and the output Haskell code. Most of the tricky work on the Haskell side is done by the Berp runtime library which implements all the primitive functions such as def, while etcetera.

Downloading Berp

Installing Berp

Using Berp

Developing Berp

Clone this wiki locally