I am implementing Burrows-Wheeler Transformation in Haskell. A combination of all cycled strings is generated and stored in a matrix as the first step of the transform. I am using Haskell List to construct the matrix. The list will store the original word on list head and its cyclic combinations down in tail.
Here is an Example of a transformed word
I have written a function that outputs the first cycled string. However, if I call the function again as a recursion, I face an infinite loop.
Here is the function
type BWT = [String] -- List of Strings for Burrows Wheeler matrix
samplebwt = ["BANANA$"] -- Sample input
rotateBWT:: BWT -> BWT
rotateBWT a = if (head (last a)) /= '$'
then [tail (head a) ++ [head (head a)]] ++ rotateBWT [tail (head a) ++ [head (head a)]]
else a
rotateBWT samplebwt
-- returns ["ANANA$B"]
--expected output ["ANANA$B", "NANA$BA", "ANA$BNA", "NA$BANA", "A$BANAN", "$BANANA"]
What am I missing?