Typeclasses - Synook/funcpy GitHub Wiki
funcpy:
Maybe => (Just value) Nothing;
a -> (Just 1);
b -> Nothing;
c v -> (? (isa v "Just") (get v "value") false);
main -> (c (Just 1));
Python:
class Type(object):
def __init__(self, option, **values):
self.option = option
self.values = values
def isa(self, option):
return lambda: self.option == option
def value(self, n):
return lambda: self.values[n]
isa = lambda: lambda type: lambda: lambda option: lambda: type.isa(option)
get = lambda: lambda type: lambda: lambda value: lambda: type.value(value)
class Maybe(Type): pass
Just = lambda: lambda value: lambda: Maybe("Just", value=value)
Nothing = lambda: Maybe("Nothing")
a = lambda: Just()(lit(1))()
b = lambda: Nothing()
c = lambda: lambda b: lambda: get()(v)()("value")() if isa()(v)()("Just")() else false();