Chad Brewbaker
Chad Brewbaker

Reputation: 2579

Haskell standard library function for transformations

Haskell has Data.List.permutations

permutations "abc" == ["abc","bac","cba","bca","cab","acb"]

Is there a standard library function for transformations or do you need to roll your own?

transformations "ab" == ["aa","ab","ba","bb"]

The Ruby way is:

 x.repeated_permutation(x.length)

Upvotes: 2

Views: 122

Answers (1)

Shoe
Shoe

Reputation: 76260

You are looking for replicateM in the Control.Monad module:

replicateM 2 "ab"
-- ["aa","ab","ba","bb"]

Live demo

AFAIK they are permutations with repetitions from the alphabet ['a', 'b'].

Upvotes: 5

Related Questions