Is it possible to be more generic ? Like here I have a tuple of 4 element but would it be possible to have an arbitrary number of element ? For instance via a monad.
More generally, replicateM does the same thing and lives in the base library. (Not sure what the advantage of variateRep would be. Better handling if eltcnt is negative, maybe? Performance?)
Hi, I found a small exercice: counting all the tuple (x1, x2, x3, x4) whose sum is equal to 18. For that I used list comprehension:
Is it possible to be more generic ? Like here I have a tuple of 4 element but would it be possible to have an arbitrary number of element ? For instance via a monad.
Something like
Issue is, I'm not sure traverse will work as I expect it to do
if I replace
undefined
by\_-> lst
it doesn't work unfortunatlyhmm actually it does weird
nvm I got my interval wrong
If you use this guy, you could do it like this:
Or more simply:
More generally,
replicateM
does the same thing and lives in thebase
library. (Not sure what the advantage ofvariateRep
would be. Better handling ifeltcnt
is negative, maybe? Performance?)Yes, I’d do:
nice functions !
Bernd Losert said:
I imagine you could even use it with
MonadComprehensions
, then it looks even more like the original.