Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More data types #6

Open
Permafacture opened this issue Jul 17, 2015 · 0 comments
Open

More data types #6

Permafacture opened this issue Jul 17, 2015 · 0 comments

Comments

@Permafacture
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant