├── .gitignore ├── ChangeLog.md ├── LICENSE ├── README.md ├── Setup.hs ├── examples └── Reverse.hs ├── proof-combinators.cabal ├── src ├── LICENSE └── LiquidHaskell │ ├── Derivations.hs │ └── ProofCombinators.hs └── stack.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | dist-* 3 | cabal-dev 4 | *.o 5 | *.hi 6 | *.chi 7 | *.chs.h 8 | *.dyn_o 9 | *.dyn_hi 10 | .hpc 11 | .hsenv 12 | .cabal-sandbox/ 13 | cabal.sandbox.config 14 | *.prof 15 | *.aux 16 | *.hp 17 | *.eventlog 18 | .stack-work/ 19 | cabal.project.local 20 | .HTF/ 21 | -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | # Revision history for src 2 | 3 | ## 0.1.0.0 -- YYYY-mm-dd 4 | 5 | * First version. Released on an unsuspecting world. 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Niki Vazou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # proof-combinators 2 | Proof combinators used in Liquid Haskell for theorem proving 3 | -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /examples/Reverse.hs: -------------------------------------------------------------------------------- 1 | {-@ LIQUID "--exactdc" @-} 2 | {-@ LIQUID "--higherorder" @-} 3 | 4 | module Reverse where 5 | 6 | import LiquidHaskell.ProofCombinators 7 | import Prelude hiding (reverse, (++), length) 8 | 9 | {-@ measure length @-} 10 | {-@ length :: [a] -> Nat @-} 11 | length :: [a] -> Int 12 | length [] = 0 13 | length (_:xs) = 1 + length xs 14 | 15 | {-@ infix : @-} 16 | {-@ reflect reverse @-} 17 | {-@ reverse :: is:[a] -> {os:[a] | length is == length os} @-} 18 | reverse :: [a] -> [a] 19 | reverse [] = [] 20 | reverse (x:xs) = reverse xs ++ [x] 21 | 22 | {-@ infix ++ @-} 23 | {-@ reflect ++ @-} 24 | {-@ (++) :: xs:[a] -> ys:[a] -> {os:[a] | length os == length xs + length ys} @-} 25 | (++) :: [a] -> [a] -> [a] 26 | [] ++ ys = ys 27 | (x:xs) ++ ys = x:(xs ++ ys) 28 | 29 | 30 | singletonP :: a -> Proof 31 | {-@ singletonP :: x:a -> { reverse [x] == [x] } @-} 32 | singletonP x 33 | = reverse [x] 34 | ==. reverse [] ++ [x] 35 | ==. [] ++ [x] 36 | ==. [x] 37 | *** QED 38 | -------------------------------------------------------------------------------- /proof-combinators.cabal: -------------------------------------------------------------------------------- 1 | name: proof-combinators 2 | version: 0.1.0.0 3 | synopsis: Proof Combinators used in Liquid Haskell for Theorem Proving 4 | 5 | homepage: http://nikivazou.github.io/ 6 | license: MIT 7 | license-file: LICENSE 8 | author: Niki Vazou 9 | maintainer: nikivazou@gmail.com 10 | 11 | category: Theorem Proving 12 | build-type: Simple 13 | extra-source-files: ChangeLog.md 14 | cabal-version: >=1.10 15 | 16 | library 17 | exposed-modules: LiquidHaskell.ProofCombinators, LiquidHaskell.Derivations 18 | build-depends: base >=4.10 && <4.11 19 | hs-source-dirs: src 20 | default-language: Haskell2010 21 | -------------------------------------------------------------------------------- /src/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Niki Vazou 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /src/LiquidHaskell/Derivations.hs: -------------------------------------------------------------------------------- 1 | -- Use theorem proving to define correct by construction functions 2 | 3 | module LiquidHaskell.Derivations ( 4 | 5 | -- * Defined, (^^^) 6 | 7 | ) where 8 | 9 | 10 | data Defined = Defined 11 | 12 | infixl 2 ^^^ 13 | x ^^^ Defined = x 14 | {-# INLINE (^^^) #-} 15 | -------------------------------------------------------------------------------- /src/LiquidHaskell/ProofCombinators.hs: -------------------------------------------------------------------------------- 1 | module LiquidHaskell.ProofCombinators ( 2 | 3 | -- Proof is just the unit type 4 | 5 | Proof, 6 | 7 | -- Proof Construction 8 | 9 | trivial, QED(..), (***), 10 | 11 | -- Equational Reasoning 12 | 13 | (==.), (==?), (?), 14 | 15 | -- Using Proofs 16 | 17 | withTheorem 18 | 19 | ) where 20 | 21 | type Proof = () 22 | 23 | trivial :: Proof 24 | trivial = () 25 | 26 | 27 | data QED = QED 28 | 29 | infixl 2 *** 30 | x *** QED = () 31 | 32 | 33 | 34 | -- | Equational Reasoning 35 | 36 | -- use (==?) to check intermediate steps 37 | -- use (==.) not to check intermediate steps 38 | 39 | infixl 3 ==., ==? 40 | 41 | (==.) :: a -> a -> a 42 | _ ==. x = x 43 | {-# INLINE (==.) #-} 44 | 45 | 46 | {-@ (==?) :: x:a -> y:{a | x == y} -> {v:a | v == y && v == x} @-} 47 | (==?) :: a -> a -> a 48 | _ ==? x = x 49 | {-# INLINE (==?) #-} 50 | 51 | -- Explanations: embed a proof into a term 52 | 53 | infixl 3 ? 54 | (?) :: a -> Proof -> a 55 | x ? _ = x 56 | {-# INLINE (?) #-} 57 | 58 | -- | Using Proofs 59 | 60 | withTheorem :: a -> Proof -> a 61 | withTheorem z _ = z -------------------------------------------------------------------------------- /stack.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-11.2 2 | 3 | packages: 4 | - . 5 | --------------------------------------------------------------------------------