These are chat archives for evhub/coconut
@evhub I love the ability to add function patterns via the
@addpattern decorator. In the name of brevity, I think it would be nice to be able to eliminate the explicit use of the decorator and have the compiler automatically detect additional patterns. However, I don't know if that's possible, nor if it is otherwise undesirable. For example, rather than writing the following (taken from your docs):
def size(Empty()) = 0 @addpattern(size) def size(Leaf(_)) = 1 @addpattern(size) def size(Node(left, right)) = size(left) + size(right)
I'd like to be able to write the following (perhaps the leading
match keyword would be helpful/necessary):
match def size(Empty()) = 0 match def size(Leaf(_)) = 1 match def size(Node(left, right)) = size(left) + size(right)
This would make it arguably cleaner (and closer to the simpler Haskell syntax). What say you? :-)
@evhub In the generated python files, the following appears:
import __coconut__ _coconut_sys.path.remove(_coconut_file_path) for name in dir(__coconut__): if not name.startswith("__"): globals()[name] = getattr(__coconut__, name)
Unfortunately, this makes such items added to the globals unresolvable within IDEs, such as PyCharm. For instance,
_coconut_MatchError cannot be resolved in an IDE. Is there any reason you don’t simply use
from __coconut__ import *, which would allow IDEs to resolve such references? Doesn’t that have the same effect as the code block above? (I’m not a Python expert, so I could very well be missing something.)
*import, which is that the “protected” members (i.e., anything with a name starting with an underscore) won’t be imported that way. However, why bother with the underscore prefixes if you’re having to do your trick above (i.e., explicitly modifying the globals)?
addpatternquestion, you may be interested in reading the discussion on #125, which was a ticket for doing something very similar. That ticket ended up getting closed because none of the other possible options seemed better.