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
= 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)
Clone this wiki locally