Projecting a list of lists efficiently in F#

后端 未结 5 627
太阳男子
太阳男子 2020-12-03 08:47

I have to do projection of a list of lists which returns all combinations with each element from each list. For example:

projection([[1]; [2; 3]]) = [[1; 2]         


        
5条回答
  •  一整个雨季
    2020-12-03 09:00

    You implementation is slow because of the @ (i.e List concat) operation, which is a slow operation and it is being done many a times in recursive way. The reason for @ being slow is that List are Linked list in functional programming and to concat 2 list you have to first go till the end of the list (one by one traversing through elements) and then append another list .

    Please look at the suggested references in comments. I hope those will help you out.

提交回复
热议问题