[Haskell-beginners] Re: Simplifying code

edgar klerks edgar.klerks at gmail.com
Wed Feb 10 05:47:09 EST 2010

He Daniel.

I have some trouble understanding what you are saying here:

>* -- first I need to find  the positions of the mutatable charachters.
No, you don't need to do that, it's in general more efficient to not care
about positions when dealing with lists.

>* findPositions :: [Char] -> [[Int]]
*>* findPositions xs = take (length index) $ index <*> [xs]
*>*         where index = elemIndices <$> leata
[f1, ..., fm] <*> [x1, ..., xn]

produces a list of length m*n, so

length (index <*> [xs]) == length index * length [xs] == length index

~> remove "take (length index) $"

About this piece of code:

fmap snd <$> fmap unzip <$> p

Prelude Control.Applicative> let p = [[[(1,2),(3,4),(4,5)]]]
Prelude Control.Applicative> fmap snd <$> fmap unzip <$> p
Prelude Control.Applicative>

But yeah, it is ridiculously complicated. And I made it up by trial
and error and looking at the types.

I have a better approach now. I am now building a tree and then walk
trough it to collect all the permutations.

Thanks for your help and effort!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100210/9b5e40f8/attachment.html

More information about the Beginners mailing list