forked from ucsd-progsys/liquidhaskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiquidClass.hs
39 lines (29 loc) · 957 Bytes
/
LiquidClass.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module LiquidClass where
-- | Typing classes
-- | Step 1: Refine type dictionaries:
class Compare a where
cmax :: a -> a -> a
cmin :: a -> a -> a
instance Compare Int where
{-@ instance Compare Int where
cmax :: Odd -> Odd -> Odd ;
cmin :: Int -> Int -> Int
@-}
cmax y x = if x >= y then x else y
cmin y x = if x >= y then x else y
-- | creates dictionary environment:
-- | * add the following environment
-- | dictionary $fCompareInt :: Compare Int
-- | { $ccmax :: Odd -> Odd -> Odd
-- | , $ccmin :: Int -> Int -> Int
-- | }
-- |
-- | Important: do not type dictionaries, as preconditions
-- | of fields cannot be satisfied!!!!!
-- | Dictionary application
-- | ((cmax Int) @fcompareInt) :: Odd -> Odd -> Odd
-- | ((cmin Int) @fcompareInt) :: Int -> Int -> Int
-- | (anything_else @fcompareInt) :: default
{-@ foo :: Odd -> Odd -> Odd @-}
foo :: Int -> Int -> Int
foo x y = cmax x y