123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109open!Base(* NOTE: Bonsai uses its own [Applicative] module so that it can make use of [%call_pos]. *)moduletypeS=sigtype'atvalreturn:here:[%call_pos]->'a->'atvalmap:here:[%call_pos]->'at->f:('a->'b)->'btvalboth:here:[%call_pos]->'at->'bt->('a*'b)tval(<*>):here:[%call_pos]->('a->'b)t->'at->'btval(<*):here:[%call_pos]->'at->unitt->'atval(*>):here:[%call_pos]->unitt->'at->'atval(>>|):here:[%call_pos]->'at->('a->'b)->'btvalapply:here:[%call_pos]->('a->'b)t->'at->'btvalmap2:here:[%call_pos]->'at->'bt->f:('a->'b->'c)->'ctvalmap3:here:[%call_pos]->'at->'bt->'ct->f:('a->'b->'c->'d)->'dtvalall:here:[%call_pos]->'atlist->'alisttvalall_unit:here:[%call_pos]->unittlist->unittmoduleApplicative_infix:sigval(<*>):here:[%call_pos]->('a->'b)t->'at->'btval(<*):here:[%call_pos]->'at->unitt->'atval(*>):here:[%call_pos]->unitt->'at->'atval(>>|):here:[%call_pos]->'at->('a->'b)->'btendendmoduletypeLet_syntax=sigtype'atmoduleOpen_on_rhs_intf:sigmoduletypeSendmoduleLet_syntax:sigvalreturn:here:[%call_pos]->'a->'atval(<*>):here:[%call_pos]->('a->'b)t->'at->'btval(<*):here:[%call_pos]->'at->unitt->'atval(*>):here:[%call_pos]->unitt->'at->'atval(>>|):here:[%call_pos]->'at->('a->'b)->'btmoduleLet_syntax:sigvalreturn:here:[%call_pos]->'a->'atvalmap:here:[%call_pos]->'at->f:('a->'b)->'btvalboth:here:[%call_pos]->'at->'bt->('a*'b)tmoduleOpen_on_rhs:Open_on_rhs_intf.SendendendmoduletypeBasic_using_map2=sigtype'atvalreturn:here:[%call_pos]->'a->'atvalmap2:here:[%call_pos]->'at->'bt->f:('a->'b->'c)->'ctvalmap:[`Define_using_map2|`Customofhere:[%call_pos]->'at->f:('a->'b)->'bt]endmoduleMake_using_map2(X:Basic_using_map2):Swithtype'at:='aX.t=structincludeXletapply~(here:[%call_pos])tfta=map2~heretfta~f:(funfa->fa)let(<*>)=applyletderived_map~(here:[%call_pos])t~f=(<*>)~here(return~heref)tletmap=matchX.mapwith|`Define_using_map2->derived_map|`Customx->x;;let(>>|)~(here:[%call_pos])tf=map~heret~fletboth~(here:[%call_pos])tatb=map2~heretatb~f:(funab->a,b)letmap3~(here:[%call_pos])tatbtc~f=map2~here(map2~heretatb~f)tc~f:(funfabc->fabc);;letall~(here:[%call_pos])ts=List.fold_rightts~init:(return~here[])~f:(map2~here~f:(funxxs->x::xs));;let(*>)~(here:[%call_pos])uv=map2~hereuv~f:(fun()y->y)let(<*)~(here:[%call_pos])uv=map2~hereuv~f:(funx()->x)letall_unit~(here:[%call_pos])ts=List.foldts~init:(return~here())~f:(funaccb->(*>)~hereaccb);;moduleApplicative_infix=structlet(<*>)=(<*>)let(*>)=(*>)let(<*)=(<*)let(>>|)=(>>|)endendmoduletypeApplicative_infix=sigtype'attype('a,'b)fn:='a->'bval(<*>):here:[%call_pos]->('a->'b)t->'at->'btval(<*):here:[%call_pos]->'at->unitt->'atval(*>):here:[%call_pos]->unitt->'at->'atval(>>|):here:[%call_pos]->'at->('a->'b,'bt)fnend