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
Better way to type Coconut data types #349
Comments
@ArneBachmann Can you give me a specific piece of code that produces the error you're encountering? |
Actual use case was a copy-constructor for data types. This didn't work:
but this did:
The only change is using makedata instead of calling the constructor. But in this code, I have to pin the copy function to a certain data type, instead of to generic data types. |
Found a generic workaround that doesn't complain in mypy and runs with any namedtuple (problem is that
|
Exposing something like above |
Current solution focusing purely on Python 3:
|
@ArneBachmann I see what's going on here. What you should do is just use |
If every data type was a namedtuple, it might work, is that what you mean as well? I'm looking for a way to type check data/named tuples generically as seen in the function above |
@ArneBachmann From MyPy's perspective, all data types should look like named tuples. |
OK I don't get it. Can you provide a minimal example on how to typecheck them datat ypes in Coco --mypy? |
@ArneBachmann For example: ~\Documents\GitHub> co --mypy
Coconut Interpreter:
(type 'exit()' or press Ctrl-D to end)
>>> try: from typing import NamedTuple
except: pass
>>> data vec(x, y)
>>> data intvec(x: int, y: int)
>>> def scale(s: int, v: NamedTuple) = v |> fmap$(-> _*s)
>>> vec(1, 1) |> scale$(2)
vec(x=2, y=2)
>>> intvec(1, 1) |> scale$(2)
intvec(x=2, y=2) As you can see, both untyped ( |
That doesn´t work... I cannot simply replace any data type with a NamedTuple. Also I want to ensure the function´s output is the same NamedTuple type, not just any one.
|
@ArneBachmann Not sure what changed, but it looks like this is just working now, so I'm closing this issue:
|
I wanted to do something like
A = TypeVar("A", bound = DA)
wheredata DA(a:int, b:str)
but it wasn't allowed to reference the_coconut
definitionsThe text was updated successfully, but these errors were encountered: