我正在尝试在 Haskell 中使用sbv解决优化问题,但出现编译器错误。
解决方案是一个值列表,我有一个检查解决方案是否有效(约束)的函数,以及一个计算最小化数字的函数。
我在我的最小示例中收到此编译器错误:
/home/t/sbvExample/Main.hs:28:5: error:
• No instance for (S.SymVal S.SBool)
arising from a use of ‘Sl.length’
• In the expression: Sl.length xs
In an equation for ‘toNum’: toNum xs = Sl.length xs
|
28 | Sl.length xs
| ^^^^^^^^^^^^
这是代码:
{-# LANGUAGE ScopedTypeVariables #-}
module Main (main) where
import qualified Data.SBV.List as Sl
import qualified Data.SBV as S
main :: IO ()
main = do
result <- S.optimize S.Lexicographic help
print result
help :: S.SymbolicT IO ()
help = do
xs :: S.SList S.SBool <- S.sList "xs"
S.constrain $ isValid xs
S.minimize "goal" $ toNum xs
isValid :: S.SList S.SBool -> S.SBool
isValid xs =
Sl.length xs S..> 0
toNum :: S.SList S.SBool -> S.SInteger
toNum xs =
Sl.length xs
所以在这个愚蠢的最小示例中,我希望一个包含一个项目的列表。
为方便起见,我将其放在 Github 上,因此使用以下命令构建它:
git clone https://github.com/8n8/sbvExample
cd sbvExample
stack build