[Haskell-cafe] Arithmetic expressions with random operators

Ingo Blechschmidt iblech at web.de
Thu Jun 8 16:20:19 UTC 2017

Dear Murad,

On Thu, Jun 08, 2017 at 04:03:55PM +0300, Mahmoud Murad wrote:
> I have the following problem, I want to randomly generate arithmetic
> expressions based on a number, for example:
> if I have n = 3, then the expression must have 3 operators like this
> (4)*(((3+5)-2)).

Mark Dominus, well-known in the Perl community, likes this puzzle so
much that he collected several solutions and nonsolutions on his blog
(which I warmly recommend). He also lists several Haskell solutions:


Ideas for further optimizations of the Haskell solutions (regarding
clarity, elegance, and length of the code) are very much welcome:



More information about the Haskell-Cafe mailing list