I'm trying to solve an optimisation problem with sbv in Haskell, but get a compiler error.
The solution is a list of values, and I have a function to check the solution is valid (the constraint), and a function to calculate a number to minimize.
I get this compiler error on my minimal example:
/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
| ^^^^^^^^^^^^
Here's the code:
{-# 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
So in this silly minimal example I would expect a list containing one item.
For convenience I put it on Github, so build it with:
git clone https://github.com/8n8/sbvExample
cd sbvExample
stack build