basic haskell: converting [[int]] to [int] -


is there easy way change [[int]] [int] or compare them in form find out if there missing elements.

for example

  set1=   [[1,2,3]]    set2= [2,3,] 

to return [1]. tried this:

return s1 s2= [x|x<-s1,y<-s2, x/=y] 

follow question: how can prevent duplicates being returned eg if

set1 = [[1,1,1,2,3] 

how can return function give me [1]

there appear approximately 3 distinct questions here.

first question, how convert list of list of ints list?

concat [[1,1,2],[2,1,3]] == [1,1,2,2,1,3] 

second question, how remove duplicates list? can use nub (remember import data.list):

nub [1,2,1,3] == [1,2,3] 

perhaps want delete consecutive duplicates? example, if know you've sorted list:

map head (group [1,1,1,2,3]) == [1,2,3] 

in that, group group them lists of consecutive duplicates, head used return first of each group of duplicates.

third question, how find items in list1 not in list2:

list1 \\ list2

be careful though, \\ mightn't operate expected if lists aren't in order , if either list includes dupes. read if want understand it's behaviour in cases.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -