Visib isible Dep e Depen ende dent nt Quan uantifjcati - - PowerPoint PPT Presentation

visib isible dep e depen ende dent nt quan uantifjcati
SMART_READER_LITE
LIVE PREVIEW

Visib isible Dep e Depen ende dent nt Quan uantifjcati - - PowerPoint PPT Presentation

Visib isible Dep e Depen ende dent nt Quan uantifjcati tifjcation on (V (VDQ) Q) Ryan Scott PL Wonks March 8, 2019 Code t Code time! me! The VDQ p he VDQ pat atch ch --- a/compiler/parser/Parser.y +++


slide-1
SLIDE 1

Visib isible Dep e Depen ende dent nt Quan uantifjcati tifjcation

  • n (V

(VDQ) Q)

Ryan Scott

PL Wonks March 8, 2019

slide-2
SLIDE 2

Code t Code time! me!

slide-3
SLIDE 3
slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6
slide-7
SLIDE 7
slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10
slide-11
SLIDE 11
slide-12
SLIDE 12

The VDQ p he VDQ pat atch ch

slide-13
SLIDE 13
  • -- a/compiler/parser/Parser.y

+++ b/compiler/parser/Parser.y +forall_vis_flag :: { ForallVisFlag } + : '.' { ForallInvis } + | '->' { ForallVis } +

  • - A ctype is a for-all type

ctype :: { LHsType GhcPs }

  • : 'forall' tv_bndrs '.' ctype {% ...

+ : 'forall' tv_bndrs forall_vis_flag ctype {% ...

  • HsForAllTy { hst_bndrs = $2

+ HsForAllTy { hst_fvf = $3 + , hst_bndrs = $2

slide-14
SLIDE 14
  • -- a/compiler/typecheck/TcHsType.hs

+++ b/compiler/typecheck/TcHsType.hs

  • -------- Foralls
  • tc_hs_type forall@(HsForAllTy { ... })

+tc_hs_type forall@(HsForAllTy { hst_fvf = fvf, ... }) = do { ...

  • ; let bndrs = mkTyVarBinders Specified tvs'

+ ; let argf = case fvf of + ForallVis -> Required + ForallInvis -> Specified + bndrs = mkTyVarBinders argf tvs'

slide-15
SLIDE 15

forall k -> k -> Type

slide-16
SLIDE 16

forall k -> k -> Type {-# LANGUAGE ExplicitForAll #-}

slide-17
SLIDE 17

Code t Code time! me!

(agai (again)

slide-18
SLIDE 18
slide-19
SLIDE 19

data F :: forall k -> k -> Type

slide-20
SLIDE 20

data F :: forall k -> k -> Type sortOfId :: forall a -> a -> a

slide-21
SLIDE 21

data F :: forall k -> k -> Type sortOfId :: forall a -> a -> a

slide-22
SLIDE 22

vdqAllowed :: UserTypeCtxt -> Bool

slide-23
SLIDE 23

vdqAllowed :: UserTypeCtxt -> Bool

  • - Currently allowed in the kinds of types...

vdqAllowed (KindSigCtxt {}) = True vdqAllowed (TySynCtxt {}) = True

slide-24
SLIDE 24

vdqAllowed :: UserTypeCtxt -> Bool

  • - Currently allowed in the kinds of types...

vdqAllowed (KindSigCtxt {}) = True vdqAllowed (TySynCtxt {}) = True

  • - ...but not in the types of terms.

vdqAllowed (FunSigCtxt {}) = False vdqAllowed (InstDeclCtxt {}) = False

slide-25
SLIDE 25
slide-26
SLIDE 26
slide-27
SLIDE 27
  • An important step towards dependent types in Haskell
  • Amaze your friends, impress your coworkers, wow!

De Debut buts s in GHC in GHC 8.10! VDQ DQ