Skip to content

Commit 29e5ee8

Browse files
committed
add card support
1 parent 70f298c commit 29e5ee8

File tree

7 files changed

+46
-2
lines changed

7 files changed

+46
-2
lines changed

liquidhaskell-boot/src/Language/Haskell/Liquid/WiredIn.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ wiredTheorySortedSyms =
113113
, "Set_sub"
114114
, "Set_add"
115115
, "Set_com"
116+
, "Set_card"
116117

117118
, "Bag_count"
118119
, "Bag_empty"

src/Data/Set_LHAssumptions.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ embed Set as Set_Set
1717
assume isSubsetOf :: (Ord a) => x:(Set a) -> y:(Set a) -> {v:Bool | v <=> Set_sub x y}
1818
assume member :: Ord a => x:a -> xs:(Set a) -> {v:Bool | v <=> Set_mem x xs}
1919
assume null :: Ord a => xs:(Set a) -> {v:Bool | v <=> Set_emp xs}
20+
assume size :: xs:(Set a) -> {v:Nat | v = Set_card xs}
2021

2122
assume empty :: {v:(Set a) | Set_emp v}
2223
assume singleton :: x:a -> {v:(Set a) | v = (Set_sng x)}
@@ -44,6 +45,7 @@ define intersection x y = (Set_cap x y)
4445
define difference x y = (Set_dif x y)
4546
define empty = (Set_empty 0)
4647
define null x = (Set_emp x)
48+
define size x = (Set_card x)
4749
define member x xs = (Set_mem x xs)
4850
define isSubsetOf x y = (Set_sub x y)
4951
define fromList xs = (Data.Set_LHAssumptions.listElts xs)

tests/neg/Card.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{-@ LIQUID "--smtsolver=CVC5" @-}
2+
module Card where
3+
4+
import Data.Set
5+
import qualified Data.Set as Set
6+
7+
8+
{-@ insert :: x:Int -> xs:[Int] -> {v:[Int] | Set.size (Set.fromList v) == Set.size (Set.fromList xs)} @-}
9+
insert :: Int -> [Int] -> [Int]
10+
insert x xs = x:xs

tests/neg/Card1.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{- LIQUID "--smtsolver=CVC5" @-}
2+
-- Z3 does not support cardinality of sets
3+
module Card where
4+
5+
import Data.Set
6+
import qualified Data.Set as Set
7+
8+
9+
{-@ insert :: x:Int -> xs:[Int] -> {v:[Int] | Set.size (Set.fromList v) >= Set.size (Set.fromList xs)} @-}
10+
insert :: Int -> [Int] -> [Int]
11+
insert x xs = x:xs

tests/pos/Card.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{-@ LIQUID "--smtsolver=CVC5" @-}
2+
module Card where
3+
4+
import Data.Set
5+
import qualified Data.Set as Set
6+
7+
8+
{-@ insert :: x:Int -> xs:[Int] -> {v:[Int] | Set.size (Set.fromList v) >= Set.size (Set.fromList xs)} @-}
9+
insert :: Int -> [Int] -> [Int]
10+
insert x xs = x:xs
11+
12+
13+
14+
{-@ insert' :: x:Int -> xs:{[Int] | not (member x (fromList xs))}
15+
-> {v:[Int] | Set.size (Set.fromList v) = 1 + Set.size (Set.fromList xs)} @-}
16+
insert' :: Int -> [Int] -> [Int]
17+
insert' x xs = x:xs

tests/tests.cabal

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,8 @@ executable unit-neg
11021102
, BigNum
11031103
, BinarySearchOverflow
11041104
, Books
1105+
, Card
1106+
, Card1
11051107
, CastedTotality
11061108
, CharLiterals
11071109
, CheckedNum
@@ -1440,7 +1442,8 @@ executable unit-pos-2
14401442
buildable: False
14411443

14421444
other-modules:
1443-
ExactADT6
1445+
Card
1446+
, ExactADT6
14441447
, ExactGADT0
14451448
, ExactGADT1
14461449
, ExactGADT2

0 commit comments

Comments
 (0)