Liquid Has iquid Haskel ell: l: Refj efjned, ned, refm fmectiv - - PowerPoint PPT Presentation

liquid has iquid haskel ell l
SMART_READER_LITE
LIVE PREVIEW

Liquid Has iquid Haskel ell: l: Refj efjned, ned, refm fmectiv - - PowerPoint PPT Presentation

Liquid Has iquid Haskel ell: l: Refj efjned, ned, refm fmectiv ective, and cl and clas assy Ryan Scott PL Wonks March 23, 2018 Refj fjnem nements ts divide :: Int -> {v:Int | v /= 0} -> Int divide n d = n `div` d Refj


slide-1
SLIDE 1

Ryan Scott

PL Wonks March 23, 2018

Liquid Has iquid Haskel ell: l:

Refj efjned, ned, refm fmectiv ective, and cl and clas assy

slide-2
SLIDE 2
slide-3
SLIDE 3

Refj fjnem nements ts

divide :: Int

  • > {v:Int | v /= 0}
  • > Int

divide n d = n `div` d

slide-4
SLIDE 4

Refj fjnem nement r ent refm efmection ction

{-@ reflect fib @-} fib :: Int -> Int fib i | i == 0 = 0 | i == 1 = 1 | otherwise = fib (i-1) + fib (i-2) fibOne :: {fib 1 == 1} fibOne = trivial *** QED

slide-5
SLIDE 5

Refj fjnem nement r t refm efmection + type ction + type clas lasses? ses?

slide-6
SLIDE 6

Refj fjnem nement r t refm efmection + type ction + type clas lasses? ses?

class Semigroup a where (<>) :: a -> a -> a

slide-7
SLIDE 7

Refj fjnem nement r t refm efmection + type ction + type clas lasses? ses?

class Semigroup a where (<>) :: a -> a -> a class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }
slide-8
SLIDE 8

Refj fjnem nement r t refm efmection + type ction + type clas lasses? ses?

class Semigroup a where (<>) :: a -> a -> a class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }
slide-9
SLIDE 9

Refj fjnem nement r t refm efmection + type ction + type clas lasses? ses?

class Semigroup a where (<>) :: a -> a -> a class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }

A t l e a s t , n

  • t

t

  • d

a y . . .

slide-10
SLIDE 10

Why Why not?

  • t?
slide-11
SLIDE 11

Wh Why y not not? Desugari Desugaring ng

class Semigroup a where (<>) :: a -> a -> a

slide-12
SLIDE 12

Wh Why y not not? Desugari Desugaring ng

class Semigroup a where -- Surface syntax (<>) :: a -> a -> a

slide-13
SLIDE 13

Wh Why y not not? Desugari Desugaring ng

class Semigroup a where -- Surface syntax (<>) :: a -> a -> a data Semigroup a {

  • - GHC core syntax

(<>) :: a -> a -> a }

slide-14
SLIDE 14

De Desugar aring ng i ins nstances es

instance Semigroup Unit where Unit <> Unit = Unit

slide-15
SLIDE 15

De Desugar aring ng i ins nstances es

instance Semigroup Unit where Unit <> Unit = Unit semigroupUnit :: Semigroup Unit semigroupUnit = Semigroup { (<>) = appendUnit } appendUnit :: Unit -> Unit -> Unit appendUnit Unit Unit = Unit

slide-16
SLIDE 16

Desugar Desugaring functions ing functions

smashList :: Semigroup a => a -> [a] -> a smashList x [] = x smashList x (y:ys) = smashList (x <> y) ys

slide-17
SLIDE 17

Desugar Desugaring functions ing functions

smashList :: Semigroup a => a -> [a] -> a smashList x [] = x smashList x (y:ys) = smashList (x <> y) ys smashList :: Semigroup a -> a -> [a] -> a smashList _ x [] = x smashList dSemigroup x (y:ys) = smashList dSemigroup ((<>) dSemigroup x y) ys

slide-18
SLIDE 18

Key i y ins nsight ht

Any refjned type involving type classes must be able to survive the translation to GHC core.

slide-19
SLIDE 19

Fi First (naï (naïve) a e) attem empt pt

class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }
slide-20
SLIDE 20

Fi First (naï (naïve) a e) attem empt pt

class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }

data VerifiedSemigroup a { semigroupSuperClass :: Semigroup a , appendAssoc :: x:a -> y:a -> z:a

  • > { (<>) d x ((<>) d y z)

== (<>) d ((<>) d x y) z } }

slide-21
SLIDE 21

Fi First (naï (naïve) a e) attem empt pt

class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }

data VerifiedSemigroup a { semigroupSuperClass :: Semigroup a , appendAssoc :: x:a -> y:a -> z:a

  • > { (<>) d x ((<>) d y z)

== (<>) d ((<>) d x y) z } }

?

slide-22
SLIDE 22

Fi First (naï (naïve) a e) attem empt pt

class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }

data VerifiedSemigroup a { semigroupSuperClass :: Semigroup a , appendAssoc :: x:a -> y:a -> z:a ->

  • > { forall d:VerifiedSemigroup a.

(<>) d x ((<>) d y z) == (<>) d ((<>) d x y) z } }

slide-23
SLIDE 23

Fi First (naï (naïve) a e) attem empt pt

class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }

data VerifiedSemigroup a { semigroupSuperClass :: Semigroup a , appendAssoc :: x:a -> y:a -> z:a ->

  • > { forall d:VerifiedSemigroup a.

(<>) d x ((<>) d y z) == (<>) d ((<>) d x y) z } }

slide-24
SLIDE 24

We e can’t sh can’t shove forall foralls withi hin pr predic dicat ates wil willy ly-n

  • nilly

ly.

Liquid Haskell is based on the quantifjer-free logic of linear arithmetic and uninterpreted functions (QF-ULIA).

{ forall d:VerifiedSemigroup a. ... } { forall d:VerifiedSemigroup a. ... }

Can’t be expressed in this system.

slide-25
SLIDE 25

Ob Obser servation ation

We can dictate the behavior of type classes in Liquid Haskell by their instances.

slide-26
SLIDE 26

Bett Better r at attem empt

class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }
slide-27
SLIDE 27

Bett Better r at attem empt

class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }

instance VerifiedSemigroup Unit where ...

slide-28
SLIDE 28

Bett Better r at attem empt

class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }

$dVSUnit :: VerifiedSemigroup Unit $dVSUnit = VerifiedSemigroup { ... } (appendAssoc $dVSUnit) :: x:a -> y:a -> z:a

  • > { (<>) $dVSUnit x ((<>) $dVSUnit y z)

== (<>) $dVSUnit ((<>) $dVSUnit x y) z && ... }

slide-29
SLIDE 29

Bett Better r at attem empt

class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }

instance VerifiedSemigroup Int where ...

slide-30
SLIDE 30

Bett Better r at attem empt

class Semigroup a => VerifiedSemigroup a where appendAssoc :: x:a -> y:a -> z:a

  • > { x <> (y <> z) == (x <> y) <> z }

$dVSInt :: VerifiedSemigroup Int $dVSInt = VerifiedSemigroup { ... } (appendAssoc $dVSInt) :: x:a -> y:a -> z:a

  • > { (<>) $dVSInt x ((<>) $dVSInt y z)

== (<>) $dVSInt ((<>) $dVSInt x y) z && ... }

slide-31
SLIDE 31

Too l

  • o lon
  • ng; di

g; didn’t w n’t wat atch ch

We begin to extend Liquid Haskell towards supporting refjnement refmection + type classes:

  • Accommodate typing rules to be instance-

aware (not as simple as it looks!)

  • Desugar refjnements involving type classes into

refjnements involving dictionaries