-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash on sat \(a :: SMaybe Word8) (b :: SMaybe Word8) -> a + b .>= 10
#598
Comments
You're breaking internal invariants by adding that {-# LANGUAGE ScopedTypeVariables #-}
import Data.SBV
import Data.SBV.Maybe as SM
test = sat $ do
mx :: SMaybe Word8 <- free "mx"
my :: SMaybe Word8 <- free "my"
constrain $ SM.isJust mx
constrain $ SM.isJust my
let x = SM.fromJust mx
y = SM.fromJust my
pure $ x + y .>= 10 I get: *Main> test
Satisfiable. Model:
mx = Just 16 :: Maybe Word8
my = Just 0 :: Maybe Word8 Does this address your problem? |
Thanks, kind of it is solves, because I got a new view on the problem. |
If you want to do it the right way, you can code it as follows: {-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
import Data.SBV
import qualified Data.SBV.Maybe as SM
lift2 :: (SymVal a, SymVal b, SymVal c) => (SBV a -> SBV b -> SBV c) -> SMaybe a -> SMaybe b -> SMaybe c
lift2 op mx my = ite (SM.isJust mx .&& SM.isJust my)
(SM.sJust (SM.fromJust mx `op` SM.fromJust my))
SM.sNothing
instance {-# OVERLAPPING #-} (Ord a, SymVal a, Num a) => Num (SBV (Maybe a)) where
(+) = lift2 (+)
(-) = lift2 (-)
(*) = lift2 (*)
abs = SM.map abs
signum = SM.map signum
fromInteger = SM.sJust . fromInteger
test :: IO SatResult
test = sat $ do
x :: SMaybe Word8 <- exists "x"
y :: SMaybe Word8 <- exists "y"
pure (x + y .>= 10) Now I get: *Main> test
Satisfiable. Model:
x = Just 21 :: Maybe Word8
y = Just 0 :: Maybe Word8 Having said that, I think the "explicit" version is preferable in this case. Too much type-class hackery like this hardly every pays off. But your mileage might vary. |
On second thought, I think you have a point that SBV can make this easier for end users. As of e9706c3, you can now say: {-# LANGUAGE ScopedTypeVariables #-}
import Data.SBV
import Data.SBV.Maybe () -- instances only
test :: IO SatResult
test = sat $ do
x :: SMaybe Word8 <- exists "x"
y :: SMaybe Word8 <- exists "y"
pure (x + y .>= 10) And get:
Note that the |
I owe SBV premium support ;) |
Hi,
I added:
Type error disappeared, but ghci started getting exception:
The text was updated successfully, but these errors were encountered: