Abstract Refinements
Very General Mechanism
Next: Lets add parameters...
11: module Composition where
12:
13: import Prelude hiding ((.))
14:
15: plus :: Int -> Int -> Int
16: plus3' :: Int -> Int
A Composed Variant
Lets define plus3
by composition
How to type compose (#) ?
This specification is too weak
80: (#) :: (b -> c) -> (a -> b) -> (a -> c)
Output type does not relate c
with a
!
Using (.) Operator
123: {-@ plus3 :: x:Int -> {v:Int | v = x + 3} @-}
124: plus3 = plus 1 . plus 2
LiquidHaskell instantiates
p
with \x -> v = x + 1
q
with \x -> v = x + 2
Using (.) Operator
138: {-@ plus3 :: x:Int -> {v:Int | v = x + 3} @-}
139: plus3 = plus 1 . plus 2
To infer that output of plus3
has type:
exists [z:{v = y + 2}].{v = z + 1}
Recap
- Refinements: Types + Predicates
- Subtyping: SMT Implication
- Measures: Strengthened Constructors
- Abstract: Refinements over Type Signatures