Sagitta is a Haskell inspired strict runtime type system for Python. The name Sagitta means ‘arrow‘ in Latin.
It uses several concepts from category theory and the Haskell type system and is usable for both object oriented and functional programming.
Arrows are morphisms (for Sets, that is functions) between categories. Essentially arrows are just typed functions between categories (with the additional requirement of having an associative composition operation). :
from sagitta.arrow import typed
from sagitta.cat import Ord, bool
from sagitta.typevar import A
@typed(A, A, bool, A = Ord)
def greater_than(a, b):
return (a > b)
Categories (typeclasses)
Categories are like Haskell typeclasses, based on abstract base classes (abc.ABCMeta and numbers): :
import sagitta.cat as cat
from cat import Category, Eq, Ord, Enum, Bounded
from cat import Number, Complex, Real, Rational, Integral
from cat import Arrow, Monad, Functor
Type variables are the 'a' in Haskell function type definitions: :
head :: [a] -> a
Equivalent in Python with Sagitta: :
@typed([A], A)
def head(lst): pass
Type constraints are the 'Eq a =>' in Haskell function type definitions: :
=/= :: Eq a => a -> a -> bool
Equivalent in Python with Sagitta: :
@typed(A, A, bool, A = Eq)
def equal(x, y):
return (x == y)
Sagitta code is at Github.