【发布时间】:2020-04-09 16:11:15
【问题描述】:
我正在尝试解决 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
【问题讨论】: