Re:Using Monads in C++ to Solve Constraints: 1. The List Monad
by beambot on Monday May 11, 2015 @06:42PM
(#9528328)
Here's one possible implementation of valueOf:
Also, in python 2.7, I don't think you can put a named variable proceeding a wildcard? At least, that doesn't work for me, so I left it out.
[ Parent
| on HN ]
Re:Using Monads in C++ to Solve Constraints: 1. The List Monad
by TheLoneWolfling on Monday May 11, 2015 @08:23PM
(#9528757)
That is a) hauling in an awfully big external library for something that should be relatively trivial, b) inefficient (you're replacing a single multiplication by 10 and addition per digit with O(log x) multiplications and an addition per digit, assuming np.power uses a decent exponentiation algorithm), and c) if anything, less readable than my version.
To put it simply, I don't see an improvement with that version.
And Python 3 has some improvements w.r.t. wildcard arguments.
Re:Using Monads in C++ to Solve Constraints: 1. The List Monad
by bpicolo on Monday May 11, 2015 @11:41PM
(#9529478)
If you don't need other bases you can just string join them. : P
Re:Using Monads in C++ to Solve Constraints: 1. The List Monad
by TheLoneWolfling on Tuesday May 12, 2015 @09:41AM
(#9531647)
That's actually how I started, and `int` has a base parameter.
But it's still relatively verbose, due to Python's whole "join-only-takes-strings" thing:
def valueOf(*values, base=10):
return int("".join(map(str, values)), base=10)
Not to mention it's doing a whole lot of unnecessary work.
Re:Using Monads in C++ to Solve Constraints: 1. The List Monad
by TheLoneWolfling on Tuesday May 12, 2015 @12:45PM
(#9533011)
Whoops. Miscopied. the second `=10` shouldn't be there.