![]() Note that the order of permutations of our function will be different from. Subpermutations (x,xs) = map (\e -> (x, e)) $ permutations xs The full code for finding all permutations of a list is below: select :: -> )] It's clear why, select creates a list ),(2,),(3,)], but we must permute sublists, which are second parts of each tuple, too! In other words, if we have (1, ), we must add (1, ) too. We can cons both parts of each tuple using uncurry (:), which has the type (a, ) ->, but we only get some permutations, not all: map (uncurry (:)) (select ) - ,] ![]() The problem is, our select is not nearly enough to generate all permutations. Here is the example of how to use select: select - ),(2,),(3,)]īefore I implemented select, I tried to find functions with type -> )] in Hayoo, there are several implementations in various libraries: However I've found even simpler implementation of select on Haskell Libraries mailing list: select :: -> )] Select' x left = (x, left++right) : select' r (x:left) rs ![]() It's task is to generate a list of tuples (a, ), where tuple's 1st part is an element from the list, and tuple's 2nd part is all elements from the list except that element. Based on answer I implemented select :: -> )] function. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |