0

我有这两个列表[@,a,@,b,c,@,@,@,(de),@,@,@,f,g,@,h]["","","+","","","?","|","","","","","*","","","|",""]我想通过使用scanl or map函数来覆盖第二个列表,并在第一个列表中提取它前面的元素。这两个列表具有不同类型的元素。

例如,如果第二个列表中的元素是/= ""然后提取第一个列表中它后面的元素(例如 for for +to get a, for ? -> c*->(de) |->g),我想要。

我尝试过这样的事情

map(\x-> if x /= "" then l2 !! (((elemIndices x l1)!!0)-1) else Epsilon)l1 

where l1 is ["","","+","","","?","|","","","","","*","","","|",""]and l2 is [@,a,@,b,c,@,@,@,(de),@,@,@,f,g,@,h]but 它不起作用,而且@ = Epsilonand 它来自data Reg = Epsilon | Literal Char | Or Reg Reg | Then Reg Reg | Star Reg deriving Eq.

有人能帮我吗 ?

4

1 回答 1

0

我想你想要类似的东西

combinedList = zip secondList (Epsilon : firstList)

然后查找“?” 你只需lookup "?" combinedList做得到Just (Literal 'c')

(您显然可以尝试抓取索引,但对于此处描述的情况来说似乎有点迂回。)

于 2013-04-23T21:00:44.137 回答