jadengeller / guac Goto Github PK
View Code? Open in Web Editor NEWMonadic do-notation in Python (requires pypy3)
Home Page: https://pypi.python.org/pypi/guac/1.0.0
License: MIT License
Monadic do-notation in Python (requires pypy3)
Home Page: https://pypi.python.org/pypi/guac/1.0.0
License: MIT License
Your example doesn't work with CPython, but it doesn't seem to work with pypy3 either:
dionyziz@puppy ~ % pypy3 4.py
Traceback (most recent call last):
File "4.py", line 29, in <module>
print(make_change(27, [1, 5, 10, 25]))
File "/usr/local/Cellar/pypy3/7.3.1_1/libexec/site-packages/guac/monad.py", line 102, in monadic_context
return monad._run(f(*args, **kwargs))
File "/usr/local/Cellar/pypy3/7.3.1_1/libexec/site-packages/guac/monad.py", line 49, in _run
return step(next(computation), computation)
File "/usr/local/Cellar/pypy3/7.3.1_1/libexec/site-packages/guac/monad.py", line 47, in step
return self.bind(monadic_value, proceed)
File "/usr/local/Cellar/pypy3/7.3.1_1/libexec/site-packages/guac/instances.py", line 32, in bind
result += f(elem)
File "/usr/local/Cellar/pypy3/7.3.1_1/libexec/site-packages/guac/monad.py", line 40, in proceed
invocation = copy.deepcopy(continuation) # Requires Pypy!
File "/usr/local/Cellar/pypy3/7.3.1_1/libexec/lib-python/3/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/local/Cellar/pypy3/7.3.1_1/libexec/lib-python/3/copy.py", line 274, in _reconstruct
y = func(*args)
File "/usr/local/Cellar/pypy3/7.3.1_1/libexec/lib-python/3/copyreg.py", line 88, in __newobj__
return cls.__new__(cls, *args)
TypeError: object.__new__(generator) is not safe, use generator.__new__()
I'm using this version:
Python 3.6.9 (?, Apr 18 2020, 02:46:07)
[PyPy 7.3.1 with GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.32.59)]
$ ipython
Python 3.7.2 (default, Feb 10 2019, 16:01:44)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from guac import *
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-2744c8a09bb7> in <module>
----> 1 from guac import *
~/.virtualenvs/monads-3hJ3DB7g/lib/python3.7/site-packages/guac/__init__.py in <module>
1 from .monad import *
2 from .instances import *
----> 3 from .functions import *
~/.virtualenvs/monads-3hJ3DB7g/lib/python3.7/site-packages/guac/functions.py in <module>
1 from .monad import *
2
----> 3 @monadic
4 def bind(m, f):
5 """
~/.virtualenvs/monads-3hJ3DB7g/lib/python3.7/site-packages/guac/monad.py in monadic(instance)
103 return monadic_context
104
--> 105 if issubclass(instance, Monad):
106 return lambda f: wrap(f, monad=instance)
107 elif not callable(instance):
~/.virtualenvs/monads-3hJ3DB7g/lib/python3.7/abc.py in __subclasscheck__(cls, subclass)
141 def __subclasscheck__(cls, subclass):
142 """Override for issubclass(subclass, cls)."""
--> 143 return _abc_subclasscheck(cls, subclass)
144
145 def _dump_registry(cls, file=None):
TypeError: issubclass() arg 1 must be a class
In [2]: %debug
> /Users/paul/.virtualenvs/monads-3hJ3DB7g/lib/python3.7/abc.py(143)__subclasscheck__()
141 def __subclasscheck__(cls, subclass):
142 """Override for issubclass(subclass, cls)."""
--> 143 return _abc_subclasscheck(cls, subclass)
144
145 def _dump_registry(cls, file=None):
ipdb> cls
<class 'guac.monad.Monad'>
ipdb> subclass
<function bind at 0x10934b730>
ipdb> u
> /Users/paul/.virtualenvs/monads-3hJ3DB7g/lib/python3.7/site-packages/guac/monad.py(105)monadic()
103 return monadic_context
104
--> 105 if issubclass(instance, Monad):
106 return lambda f: wrap(f, monad=instance)
107 elif not callable(instance):
ipdb> instance
<function bind at 0x10934b730>
ipdb> issubclass(instance, Monad)
*** TypeError: issubclass() arg 1 must be a class
ipdb> u
> /Users/paul/.virtualenvs/monads-3hJ3DB7g/lib/python3.7/site-packages/guac/functions.py(3)<module>()
1 from .monad import *
2
----> 3 @monadic
4 def bind(m, f):
5 """
ipdb>
$ pip freeze | grep guac
guac==1.0.0
ython 3.5.3 (a39af0be3a22, Jun 05 2017, 20:18:00)
[PyPy 5.8.0-beta0 with GCC 6.2.0 20160901] on linux
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``why there is no "PyPy 1.4
released" in topic any more?''
>>>> guac.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'guac' is not defined
>>>> execfile("guac.py")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'execfile' is not defined
>>>> exec(open("guac.py").read(),globals())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 158, in <module>
File "<string>", line 103, in monadic_context
File "<string>", line 50, in _run
File "<string>", line 48, in step
File "<string>", line 129, in bind
File "<string>", line 41, in proceed
File "/home/user/pypy3/lib-python/3/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/user/pypy3/lib-python/3/copy.py", line 292, in _reconstruct
y = callable(*args)
File "/home/user/pypy3/lib-python/3/copyreg.py", line 88, in __newobj__
return cls.__new__(cls, *args)
TypeError: object.__new__(generator) is not safe, use generator.__new__()
@JadenGeller I'm using pypy3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.