Skip to content

rorodata/hypertype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

(↑t) - hypertype

Haskell-inspired type system and pattern matching for Python.

Examples

from hypertype import *

Circle = Record({
    "type": Literal("circle"),
    "radius": Integer
})
Rectangle = Record({
    "type": Literal("rectangle"),
    "length": Integer,
    "width": Integer
})

Shape = Circle | Rectangle

@method
def area(c: Circle):
    return 3.14*c['radius']*c['radius']

@method
def area(r: Rectangle):
    return r['length']*r['width']

c = {
    "type": "circle",
    "radius": 5
}
r = {
    "type": "rectangle",
    "length": 10,
    "width": 4
}

print(Shape.valid(c), Shape.valid(r))
print(area(c), area(r))

Checkout out examples directory for more examples.

About

Haskell-inspired type system and pattern matching for Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages