my - cs.ox.ac.ukko-lecture2.pdf · plan • review well-behavedness, with partiality explicitly...

14
BiGUL’s Bidirectionality Zhenjiang Hu & Josh Ko National Institute of Informatics, Japan Oxford Summer School on Bidirectional Transformations 27 July 2016

Upload: others

Post on 30-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

BiGUL’sBidirectionality

ZhenjiangHu&JoshKoNationalInstituteofInformatics,Japan

OxfordSummerSchoolonBidirectionalTransformations 27July2016

Page 2: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

Plan• Reviewwell-behavedness,withpartialityexplicitlyrepresented.

• Getatasteofputback-baseddesignbylookingatseveralBiGULconstructs.

• Startwithanaturalputsemantics,andthenreviseitsothatacorrespondinggetexists.

Page 3: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

(Well-behaved)Lensput::s->v->Maybesget::s->Maybev

PutGet

GetPut

Page 4: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

UniquenessofgetForanylenseslandr,putl=putr==>getl=getr

Proof

Page 5: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

Replace::BiGULvvputReplacesv=Justv

Page 6: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

Skip::BiGULsv(?)putSkipsv=Justs

Page 7: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

Skip::(s->v)->BiGULsvput(Skipf)sv=ifv==fsthenJustselseNothing

joshko
Sticky Note
courtesy of Robby Findler
Page 8: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

Prod::BiGULslvl->BiGULsrvr->BiGUL(sl,sr)(vl,vr)

put(l`Prod`r)(sl,sr)(vl,vr)=dosl’<-putlslvlsr’<-putrsrvrreturn(sl’,sr’)

get(l`Prod`r)(sl,sr)=dovl<-getlslvr<-getrsrreturn(vl,vr)

Page 9: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

PutGetforProdAssumeput(l`Prod`r)(sa,sb)(va,vb)=Just(sa’,sb’)

Proveget(l`Prod`r)(sa’,sb’)=(va,vb)

(dosl’<-putlsavasr’<-putrsbvbreturn(sl’,sr’))=Just(sa’,sb’)

(dovl<-getlsa’vr<-getrsb’return(vl,vr))=Just(va,vb)

Page 10: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

PutGetforProd(dosl’<-putlsavasr’<-putrsbvbreturn(sl’,sr’))=Just(sa’,sb’)

∃sl’.putlsava=Justsl’∧∃sr’.putrsbvb=Justsr’∧Just(sl’,sr’)=Just(sa’,sb’)

putlsava=Justsa’∧putrsbvb=Justsb’

Page 11: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

PutGetforProdAssumeputlsava=Justsa’putrsbvb=Justsb’

Provegetlsa’=Justvagetrsb’=Justvb

Page 12: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

Case(binary)

put(Case(pl,l)(pr,r))sv=ifplsvthenputlsvelseifprsvthenputrsvelseNothing

typeCaseBranchsv=(s→v→Bool,BiGULsv)

Case::CaseBranchsv->CaseBranchsv->BiGULsv

Page 13: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

Case(withexitconditionsandadaptation)typeCaseBranchsv=(s→v→Bool,BiGULsv,s->Bool)

typeCaseAdaptiveBranchsv=(s->v->Bool,s->v->s)

Case::CaseBranchsv->CaseBranchsv->CaseAdaptiveBranchsv->BiGULsv

Page 14: My - cs.ox.ac.ukKo-lecture2.pdf · Plan • Review well-behavedness, with partiality explicitly represented. • Get a taste of putback-based design by looking at several BiGUL constructs

Rearrangement• $(rearrV[|\(Left(x,y))->(y,x)|])…

• Key:patternmatchingandexpressionevaluationareinvertible

• Type-safeimplementationwithHaskell’sgeneralisedalgebraicdatatypes