GithubHelp home page GithubHelp logo

hapy's People

Contributors

aupiff avatar ddfisher avatar npezolano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hapy's Issues

Improper module loading..

This is a peculiar bug which I experience on python 2.7.3

To reproduce, load any module from HaPy in python interpreter.. after which you cannot load

$ python
Python 2.7.3 (default, Feb 27 2014, 20:00:17) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'successful import of json module, it can be any module for that matter'
successful import of json module, it can be any module for that matter
>>> import json
>>> 
>>> from HaPy import ExampleModule
>>> 
>>> import yaml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named yaml
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from io import StringIO
ImportError: No module named io

Original exception was:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named yaml

I checked the sys.modules after loading the HaPy module and found it intact (to verify possibility if loading HaPy corrupts it)
The issue is in loading the module somewhere, my bet is on load_module function..

Special ASCII Character are dropped

Special ASCII characters like '\NUL' and '\DEL' are dropped when called from python, to reproduce..

MyModule.hs

sFunc :: String                                                                 
sFunc = "b\NUL\DELa"

Calling it from Python

>> from HaPy import MyModule as mm
>> mm.sFunc()
>> 'b'

/usr/bin/ld: Export.o: relocation R_X86_64_32S against `stg_upd_frame_info'

Yours is the most recently updated project I could find as far as calling Haskell shared libraries from python. I get this linker error when trying to make your example. Thanks for sharing this project!

nelson@cesium:~/projects/interweave/HaPy/example$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.6.3

nelson@cesium:~/projects/interweave/HaPy/example$ make all
ghc --make -no-hs-main -optl '-shared' HaPy_init.c -o ExampleModule.so Export.hs
[1 of 2] Compiling ExampleModule ( ExampleModule.hs, ExampleModule.o )
[2 of 2] Compiling Export ( Export.hs, Export.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading object (static) HaPy_init.o ... done
final link ... done
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package containers-0.5.0.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package th-lift-0.5.5 ... linking ... done.
Loading package HaPy-0.1.0.0 ... linking ... done.
Linking ExampleModule.so ...
/usr/bin/ld: Export.o: relocation R_X86_64_32S against `stg_upd_frame_info' can not be used when making a shared object; recompile with -fPIC
Export.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [all] Error 1

More data types

I've been interested in making a strict typed system in Python that would be mapable to Haskell.

Type enforcement could be as expensive as we want, and done through assert statements. Asserts go away when the program is compiled with optimization. Ie: python -O myprog.py. Thus in testing, we can iterate through a list just to check that every element is actually an integer, and in deployment we can be confident that lies won't happen and get a seg fault or something if it does.

For instance, if you had

    #haskell
    data Point = Point Float Float
    data Line = Line Point Point

    lineLinesIntersect :: Line -> [Line] -> [Maybe Point]
    --etc.

Then in python one could have:

    #@haskell("Int(a) WorldObject(b) => [a] -> b -> [Maybe Point]") 
    @haskell("f -> [Maybe Point]")
    def line_lines_intersect(indexs,world_object):
        #put together a line and some lines in python

        #haskell.lineLinesIntersect obviously type enforces before calling haskell
        return haskell.lineLinesIntersect(line,lines)

So python functions could be strictly typed, or not. And haskell functions would get garunteed structures suitable for the type constructor. It's cool how Haskell's polymorphism is (or can be) like duck typing and python's class heirarchy, so one could go nuts with this if they wanted to. I think just the minimal to get into Haskell land is enough.

Some mapping of Nothing to None would be awesome. Exceptions could also be passed this way.

Haskell records are so much like named tuples, I think it might make sense to require the Haskell side to define everything as records. These could easily become c structs, Right? But I really don't know enough about the details of communication to know what make sense.

Anyways, I think this is all cool to think about, but would anything I can do towards this help HaPy support, uh, algebraic data types, or custom data types, or whatever they're called? I'm solid with Python and Linux but a noob at Haskell and ctypes/ffi.

usage with stack

I tried to use HaPy with stack, but failed. Could you please update the example?

What I found up to now is: the extra libraries options has to go to stack.yaml, e.g.

ghc-options:
    package-name:    -lHSrts-ghc7.10.3

The _.so file will be somewhere in .stack-work/install/x86_64-linux/lts-5.8/7.10.3/lib/x86_64-linux-ghc-7.10.3/modulename_/lib*.so. (Tough I haven't used--enable-shared anywhere, how'd I supply that to stack?) So far so good. Copying that *.so-file to the python directory and using it there gives me:

OSError: /usr/lib/ghc/ghcpr_8TmvWUcS1U1IKHT0levwg3/libHSghc-prim-0.4.0.0-8TmvWUcS1U1IKHT0levwg3-ghc7.10.3.so: undefined symbol: stg_forkOnzh

Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.