I want to create a rec function, say oddleninLdbl, that takes as an argument a list of lists "L" and returns a copy of "L" in which the lists of odd length have been "doubled" - doubled here means the list will concatenate with itself.
To illustrate the above, the idea is to have this :
oddleninLdbl [[]; [5]; [23;5]; [45;65;2]; []; [34;85;7;22;1]];;
returns the following:
[[]; [5;5]; [23;5]; [45;65;2;45;65;2]; []; [34;85;7;22;1;34;85;7;22;1]]
it should also work with whatever list type, again for example this here with strings:
oddleninLdbl [[]; ["mi";"lo"]; ["la"]; ["lo";"co";"mo"]]
should return:
[[]; ["mi";"lo"]; ["la";"la"]; ["lo";"co";"mo";"lo";"co";"mo"]]
I've been running in circles around this one. If I'm not mistaken, I know that my 'if expression' should revolve around something related to the length of the lists within a list, and when it is List.length mod 2 = 1 the sub-list should concatenate with itself.
But, I'm unable to apply it as I've never worked with list of lists! How should this function be written? Your help is much appreciated.
Aucun commentaire:
Enregistrer un commentaire