True
is a bad argument10
is a good argument0
average
take
fib
fib
is an uninterpreted function
Verification of Haskell Code with SMTs
Follow online http://goto.ucsd.edu/~nvazou/presentations/cufp16/01-index.html
Motivation: Why verification?
λ> :m +Data.Text Data.Text.Unsafe
λ> let text = pack "Niki"
λ> :t takeWord16
takeWord16 :: Int -> Text -> Text
True
is a bad argumentλ> takeWord16 True text
<interactive>:5:12:
Couldn't match expected type ‘Int’ with actual type ‘Bool’
In the first argument of ‘takeWord16’, namely ‘True’
In the expression: takeWord16 True text
10
is a good argument6
extra characters... λ> takeWord16 10 text
"Niki\33624\5479\SOH\NUL\60480\5115"
λ> :t head
head :: [a] -> a
λ> head "CUFP"
'C'
λ> head []
*** Exception: Prelude.head: empty list
λ> fib 1 <= fib 42
False
λ> mapReduce 42 sum (+) [1..20]
0
To prevent wider class of errors
To enforce program specific properties
Follow online http://goto.ucsd.edu/~nvazou/presentations/cufp16/01-index.html
Diverse Code Bases
10KLoc / 56 Modules
Memory Safety, Termination, Functional Correctness
Inference is Crucial
Specifications: 1 / 10 LOC (ok)
Compile Time: 1s / 10 LOC (not ok!)
Library | LOC | Specs | Time |
---|---|---|---|
XMonad.StackSet |
256 | 74 | 27s |
Data.List |
814 | 46 | 26s |
Data.Set.Splay |
149 | 27 | 27s |
Data.Vector.Algorithms |
1219 | 76 | 89s |
HsColour |
1047 | 19 | 196s |
Data.Map.Base |
1396 | 125 | 174s |
Data.Text |
3128 | 305 | 499s |
Data.Bytestring |
3505 | 307 | 294s |
Total | 11512 | 977 | 1336s |
Refinement Types: Automated Dependent Typing via SMT
Properties: | Predicates + Types |
Proofs: | SMT Solvers + Subtyping |
Inference: | Abstract Interpretation + Hindley-Milner |
cabal install liquidhaskell
http://www.refinement-types.org
online demo @ http://goto.ucsd.edu/liquidhaskell