These are chat archives for evhub/coconut

Dec 2016
Evan Hubinger
Dec 05 2016 02:05

@eshansingh Type annotations as you wrote them are actually already supported! Coconut supports Python 3.6 type annotation syntax, which includes function argument, return value, and variable annotations, all of which get compiled to version-independent, MyPy-compatible type comments/annotations. Ideally, I would like to improve on that by adding syntax for specific MyPy constructs (e.g. compile a -> b inside of a type definition to typing.Callable[a, b]), but I'm not yet sure what I want that syntax to look like. As for monads and ADTs, data can actually be used for both when combined with pattern-matching--here are some examples:

ADT example:

data Empty()
data Leaf(n)
data Node(l, r)

def size(Empty()) = 0

def size(Leaf(n)) = 1

def size(Node(l, r)) = size(l) + size(r)

size(Node(Empty(), Leaf(10))) == 1

Monad example:

data Nothing():
    def __call__(self, *args):
        return Nothing()
    def __eq__(self, other):
        match Nothing() in other:
            return True
            return False

data Just(item):
    def __call__(self, *args):
        return Just <| reduce((|>), args, self.item)
    def __eq__(self, other):
        match Just(item) in other:
            return self.item == item
            return False

Maybe = (Nothing, Just)

Just(5) <| (**)$(?, 2) <| (+)$(1) == Just(26)
Eshan Singh
Dec 05 2016 03:16
@evhub Oh, I see what you mean.