playing with berp: python3 to haskell compiler in haskell

Discussion in 'Python' started by Alia Khouri, Oct 31, 2010.

  1. Alia Khouri

    Alia Khouri Guest

    In case anyone finds this worthwhile: there is a pretty impressive
    python3 to haskell compiler written in haskell called berp that looks
    very interesting: http://github.com/bjpop/berp/wiki

    I highly recommend reading through the berp implementation code for a
    fascinating (but currently incomplete) attempt at a purely functional
    implementation of python3. The current version doesn't do floats and
    imports and other things but includes callcc continuations and tail-
    call optimization, and it is likely these things will be added
    relatively quickly as the code is extremely well-structured.

    Even the generated code (minus the underscore) is surprisingly
    readable:

    <python>
    class Person:
    def __init__(self, name):
    self.name = name

    def say_hello(self):
    print('hello, my name is '+self.name)

    def main():
    p = Person('sam')
    p.say_hello()

    main()
    </python>

    to

    <haskell>
    module Main where
    import Berp.Base
    import qualified Prelude
    main = runStmt init
    init
    = do _s_Person <- var "Person"
    _s_main <- var "main"
    klass "Person" _s_Person []
    (do _s___init__ <- var "__init__"
    _s_say_hello <- var "say_hello"
    def _s___init__ 2 none
    (\ [_s_self, _s_name] ->
    do _t_0 <- read _s_name
    _t_1 <- read _s_self
    setattr _t_1 (621807930, "_s_name") _t_0)
    def _s_say_hello 1 none
    (\ [_s_self] ->
    do _t_2 <- read _s_print
    _t_3 <- read _s_self
    _t_4 <- _t_3 . (621807930, "_s_name")
    _t_5 <- string "hello, my name is " + _t_4
    _t_2 @@ [_t_5])
    pure
    [((-277916325, "_s___init__"), _s___init__),
    ((175397596, "_s_say_hello"), _s_say_hello)])
    def _s_main 0 none
    (\ [] ->
    do _s_p <- var "p"
    _t_6 <- read _s_Person
    _t_7 <- _t_6 @@ [string "sam"]
    _s_p =: _t_7
    _t_8 <- read _s_p
    _t_9 <- _t_8 . (175397596, "_s_say_hello")
    _t_9 @@ [])
    _t_10 <- read _s_main
    _t_10 @@ []

    </haskell>



    Also see: others ways to interface to haskell code (from ctypes for
    example, see my entry in http://wiki.python.org/moin/PythonVsHaskell)

    AK
     
    Alia Khouri, Oct 31, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xah Lee

    a Haskell a Day

    Xah Lee, Oct 26, 2005, in forum: Java
    Replies:
    10
    Views:
    626
    Wil Hadden
    Oct 28, 2005
  2. Isaac Jones

    Haskell distutils-type system

    Isaac Jones, Jul 1, 2003, in forum: Python
    Replies:
    2
    Views:
    352
    Donn Cave
    Jul 3, 2003
  3. Casey Hawthorne
    Replies:
    3
    Views:
    334
  4. Replies:
    1
    Views:
    151
    Tad McClellan
    Mar 15, 2005
  5. Andrew Berg
    Replies:
    0
    Views:
    335
    Andrew Berg
    Jun 16, 2012
Loading...

Share This Page