Haskell不在范围内double where子句

时间:2014-01-01 19:37:27

标签: haskell scope

当我尝试编译它时,它告诉我b不在范围内。虽然我已经为b包含了where子句。不要理会类型同义词。

buildBDD :: BExp -> [ Index ] -> BDD
buildBDD exp inds = snd ( buildBDD' exp 1 inds [])
                  where
                   buildBDD' :: BExp -> Id -> [ Index ] -> [ ( Index, Bool ) ]
                                -> ( Id, BDD )
                   buildBDD' exp ind [] env       
                      = (b, [])
                   buildBDD' exp ind (i : is) env 
                      = buildBDD' exp i is [(ind, True)]
                      where    
                        b = if eval exp env then -1 else -2

2 个答案:

答案 0 :(得分:1)

where子句仅适用于单行定义,因此您的第二个where子句仅适用于单个定义 buildBDD' exp ind (i : is) env。您需要将其向上移动,以使其适用于先前的定义。

答案 1 :(得分:1)

您需要将where范围添加到正确的模式匹配中!像if eval exp env这样的东西甚至可能没有意义,如果你把它放到错误的模式定义,因为例如此时没有env个变量匹配。

    buildBDD' exp ind [] env = (b, [])
             where b | eval exp env  = -1
                     | otherwise     = -2                   
    buildBDD' exp ind (i : is) env 
                  = buildBDD' exp i is [(ind, True)]
相关问题