Skip to content

Instantly share code, notes, and snippets.

@LeventErkok
Created February 3, 2015 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeventErkok/163362a59060188f5e62 to your computer and use it in GitHub Desktop.
Save LeventErkok/163362a59060188f5e62 to your computer and use it in GitHub Desktop.
Using uninterpreted types/functions to simulate fake polymorphism
{-# LANGUAGE DeriveDataTypeable #-}
import Data.SBV
import Data.Generics
-- boilerplate to get A to be an SMT-Lib uninterpreted sort
data A = A () deriving (Eq, Ord, Data, Typeable, Read, Show)
instance SymWord A
instance HasKind A
type SA = SBV A
-- define the various injections we'd like to use:
class ToA x where
toA :: SBV x -> SA
instance ToA Integer where toA = uninterpret "int2A"
instance ToA Bool where toA = uninterpret "bool2A"
-- This is the prop function that works over the uninterpreted sort A
prop :: SA -> SBool
prop = uninterpret "prop"
-- Get a simple sat result; note the explicit injections
test :: IO SatResult
test = sat $ do x1 <- sInteger "x1"
x2 <- sBool "x2"
return $ prop (toA x1) &&& prop (toA x2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment