diff --git a/categories/img/mp/graph.mp b/categories/img/mp/graph.mp index af82dd2..954f33b 100644 --- a/categories/img/mp/graph.mp +++ b/categories/img/mp/graph.mp @@ -25,7 +25,14 @@ green :=(0.52156862745098 ,0.6 ,0.0); %%%%%%%%%%%%%%%%%%%% u:=.5cm; % unity gu:=5u; % distance between states -nodesize := 1.2u; %size of a node +nodesize := u + .1cm; %size of a node + +def resize(expr nu)= + u:=nu; + gu:=5u; % distance between states + nodesize := u; %size of a node + nodespace := u+.1cm; %size of a node +enddef; % return the middle of a path vardef midpoint(expr p)= @@ -91,7 +98,7 @@ vardef edgeFull(expr posA,posB,inan,outan) = path sub; path s; s := posA {dir inan} .. {dir outan} posB ; - sub := shorten(s,nodesize); + sub := shorten(s,nodespace); sub enddef; @@ -138,16 +145,22 @@ enddef; %% LOOPS %% %% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +vardef dist(expr a,b)= + numeric width,height,res; + width:=xpart b - xpart a; + height:=ypart b - ypart a; + res:=sqrt(width*width + height*height); +enddef; % return a loop vardef loopFull(expr a,b,an) = pair ba,ea; path circ,p,s; p:=a{1,1}..b..{1,-1}cycle; - circ:= fullcircle scaled nodesize shifted a; + circ:= fullcircle scaled nodespace shifted a; ba = circ intersectionpoint (subpath (0,1) of p); ea = circ intersectionpoint (subpath (1,2) of p); s:= ba{1,1}..b..{1,-1}ea; - s rotated an + s shifted -a rotated an shifted a enddef; vardef loopPoint(expr a,b) = @@ -195,21 +208,23 @@ enddef; % draw some state with some label insize def drawState(expr pos,l) = % Draw the circle - draw fullcircle scaled u shifted pos; + draw fullcircle scaled nodesize shifted pos; % Draw the label with the right size picture lab,reslab; numeric height,width; numeric size; - lab=thelabel(TEX("$"&l&"$"),pos); + lab=thelabel(TEX("$"&l&"$"),origin); height:=ypart (ulcorner lab - llcorner lab); width :=xpart (urcorner lab - ulcorner lab); size := sqrt(height*height + width*width); - if size>u: - reslab:=lab scaled (u/size); + if size>.9nodesize: + reslab:=lab scaled (.9nodesize/size) shifted pos; else: - reslab:=lab; + reslab:=lab shifted pos; fi + % help for debug to draw boundaries + % draw ulcorner reslab -- urcorner reslab -- lrcorner reslab -- llcorner reslab -- cycle; draw reslab; enddef; diff --git a/categories/img/mp/hask-endofunctor.mp b/categories/img/mp/hask-endofunctor.mp new file mode 100644 index 0000000..c67a0d5 --- /dev/null +++ b/categories/img/mp/hask-endofunctor.mp @@ -0,0 +1,66 @@ +pair int,bool,func,intlist,list; +resize(.8cm); +int=origin; +% drawoptions (withcolor baseOne withpen pencircle scaled 1.2); + +intlist=int shifted (gu,0); +func=int shifted (0,-.6gu); +bool=func shifted (gu,0); +list=func shifted (2u,0); + +drawState(int,"\mathtt{Int}"); +drawState(bool,"\mathtt{Bool}"); +drawState(func,"\mathtt{a\rightarrow b}"); +drawState(intlist,"\mathtt{[Int]}"); +drawState(list,"\mathtt{[a]}"); + +drawLoopPoint(int,int shifted (0,1.6u),"\mathtt{sqrt}"); +drawEdge(int,int,"\mathtt{id}"); +drawEdgeAngle(int,bool,"\mathtt{odd}",-30); +drawEdgeAngle(int,bool,"\mathtt{even}",30); +drawEdge(intlist,intlist,"\mathtt{tail}"); +drawEdge(intlist,int,"\mathtt{head}"); + +pair decal; +pair fint,fbool,ffunc,fintlist,flist; +decal := (1.7gu,0); +fint=int shifted decal; +fintlist=intlist shifted decal; +ffunc= func shifted decal; +fbool= bool shifted decal; +flist= list shifted decal; + +drawState(fint,"\mathtt{F\ Int}"); +drawState(fbool,"\mathtt{F\ Bool}"); +drawState(ffunc,"\mathtt{F\ a\rightarrow b}"); +drawState(fintlist,"\mathtt{F\ [Int]}"); +drawState(flist,"\mathtt{F\ [a]}"); + +drawLoopPoint(fint,fint shifted (0,1.6u),"\mathtt{sqrt}"); +drawEdge(fint,fint,"\mathtt{id}"); +drawEdgeAngle(fint,fbool,"\mathtt{odd}",-30); +drawEdgeAngle(fint,fbool,"\mathtt{even}",30); +drawEdge(fintlist,fintlist,"\mathtt{tail}"); +drawEdge(intlist,int,"\mathtt{head}"); + +drawblock(fint,fbool,"\mathtt{F}"); + +pair ff; +ff = .5[fint,fintlist] shifted (0,u); +path b; +b := block(origin,origin); +draw b scaled .5 shifted ff; +label.top(btex $\mathtt{F\ F}$ etex, blockLabelPosition(b)) scaled .5 shifted ff; +draw b scaled .25 shifted ff; +label.top(btex $\mathtt{F\ F\ F}$ etex, blockLabelPosition(b)) scaled .25 shifted ff; + +drawoptions(withcolor yellow withpen pencircle scaled 1 dashed evenly); +drawarrow edgeAngle(int,fint,45); +drawoptions(withcolor green withpen pencircle scaled 1 dashed evenly); +drawarrow edgeAngle(intlist,fintlist,-20); +drawoptions(withcolor blue withpen pencircle scaled 1 dashed evenly); +drawarrow edgeAngle(func,ffunc,-25); +drawoptions(withcolor red withpen pencircle scaled 1 dashed evenly); +drawarrow edgeAngle(list,flist,25); +drawoptions(withcolor orange withpen pencircle scaled 1 dashed evenly); +drawarrow edgeAngle(bool,fbool,-25); diff --git a/categories/img/mp/hask-endofunctor.png b/categories/img/mp/hask-endofunctor.png new file mode 100644 index 0000000..f4133c0 Binary files /dev/null and b/categories/img/mp/hask-endofunctor.png differ diff --git a/categories/img/mp/hask.mp b/categories/img/mp/hask.mp new file mode 100644 index 0000000..85ed72b --- /dev/null +++ b/categories/img/mp/hask.mp @@ -0,0 +1,22 @@ +pair int,bool,func,intlist,list; +resize(.8cm); +int=origin; +% drawoptions (withcolor baseOne withpen pencircle scaled 1.2); + +intlist=int shifted (gu,0); +func=int shifted (0,-.6gu); +bool=func shifted (gu,0); +list=func shifted (2u,0); + +drawState(int,"\mathtt{Int}"); +drawState(bool,"\mathtt{Bool}"); +drawState(func,"\mathtt{a\rightarrow b}"); +drawState(intlist,"\mathtt{[Int]}"); +drawState(list,"\mathtt{[a]}"); + +drawLoopPoint(int,int shifted (0,1.6u),"\mathtt{sqrt}"); +drawEdge(int,int,"\mathtt{id}"); +drawEdgeAngle(int,bool,"\mathtt{odd}",-30); +drawEdgeAngle(int,bool,"\mathtt{even}",30); +drawEdge(intlist,intlist,"\mathtt{tail}"); +drawEdge(intlist,int,"\mathtt{head}"); diff --git a/categories/img/mp/hask.png b/categories/img/mp/hask.png new file mode 100644 index 0000000..b0293ba Binary files /dev/null and b/categories/img/mp/hask.png differ