Re: Generating all permutations of a list in Haskell

楼主: scwg ( )   2010-06-22 02:11:24
※ 引述《slyfox (klanloss)》之铭言:
: I was tracing the code from:
: http://shivindap.wordpress.com/2009/01/12/permutations-of-a-list-in-haskell/
: but got confused by:
: permutation [1]
: = [ 1 : permutation [] ]
: = [ 1 : [[]] ]
: where did i go wrong? Thanks.
permutation [] = [ [] ]
permutation xs = [ x:ys | x <- xs, ys <- permutation (delete x xs) ]
permutation [1] = [ 1:ys | ys <- permutation [] ]
= [ 1:ys | ys <- [ [] ] ]
= [ 1:[] ] = [ [1] ]
作者: slyfox (klanloss)   2010-06-22 08:15:00
thx

Links booklink

Contact Us: admin [ a t ] ucptt.com