什么是集合的deleteFindMin的替代方法?

时间:2018-03-31 18:00:21

标签: haskell set

Data.Set.deleteFindMin的等效函数对于集合的使用是什么? 我创建了以下类型:

  

输入SofSes = Set.Set(Set.Set String)

我需要的是选择第一组并将其返回:

  

{{firstSet},{secondSet},...,{n-thSet}} - > ({firstSet},{{secondSet},...,{正thSet}})

deleteFindMin的错误消息:

Couldn't match type `Set.Set String' with `[t0]'
    Expected type: Set.Set [t0]
      Actual type: Set.Set (Set.Set String)

我的代码:

reduce ts   
    | (Set.null (setW ts))==False = do                                   
        reduce (firstFor (Set.deleteFindMin (setW ts)) (getAlphabet ts)                                              
    | otherwise = ts


firstFor (a,w) (c:cs) ts                                                                   
    | null(c:cs)==False = do 
        secondFor (fromCtoA a c ts) ts                                            
    | otherwise =  ts

fromCtoA (a:as) c ts = ts  --function that is not finished yet (TODO)    

data KAutomat = KA
    { states :: Set.Set String
    , start :: KState
    , final :: Set.Set String
    , trans :: [Transition]
    , setW :: Set.Set (Set.Set String)
    , setP :: Set.Set (Set.Set String)
    } deriving (Eq)

变量ts的类型为KAutomat。

1 个答案:

答案 0 :(得分:1)

我可以为您强调代码中的一个冲突,但是根据给出的信息,可能无法说出正确的修复方法。 (我已经在你的问题上发表评论,描述了我希望你提出的努力,这样可以提供更具体的帮助。)

这是冲突。你写了

fromCtoA (a:as) c ts = ts

,由于a:as只能是一个列表,我们得出结论:fromCtoA必须将列表作为其第一个参数。你也写道:

reduce ... = ... firstFor (Set.deleteFindMin (setW ts)) ...
firstFor (a,w) ... = ... fromCtoA a ...

由于setW返回Set (Set String)deleteFindMin来电将返回(Set String, Set (Set String)),因此a将为Set String,我们得出结论,fromCtoA必须接受Set String作为其第一个参数。这与我们之前的结论不一致,fromCtoA只能接受列表。

相关问题