on master help sign in
Start using custom infix definitions.
b9ae74bevancz
core-elm/Automaton.elm+3−6
@@ -42,20 +42,17 @@ run (Automaton m0) input =
42step (Automaton m) a = m a
42step (Automaton m) a = m a
43
43
44
44
45−--a1 >>> a2 =
45+a1 >>> a2 =
46−composeAuto a1 a2 =
47 let { Automaton m1 = a1 ; Automaton m2 = a2 } in
46 let { Automaton m1 = a1 ; Automaton m2 = a2 } in
48 Automaton
47 Automaton
49 (\a -> let (b,m1') = m1 a in
48 (\a -> let (b,m1') = m1 a in
50− let (c,m2') = m2 b in (c, composeAuto m1' m2'))
49+ let (c,m2') = m2 b in (c, m1' >>> m2'))
51
50
52−{--
53−a2 <<< a1 = a1 >>> a2
51+a2 <<< a1 = a1 >>> a2
54f ^>> a = pure f >>> a
52f ^>> a = pure f >>> a
55a >>^ f = a >>> pure f
53a >>^ f = a >>> pure f
56f ^<< a = a >>> pure f
54f ^<< a = a >>> pure f
57a <<^ f = pure f >>> a
55a <<^ f = pure f >>> a
58−--}
59
56
60combine autos =
57combine autos =
61 Automaton (\a -> let (bs,autos') = unzip $ map (\(Automaton m) -> m a) autos in
58 Automaton (\a -> let (bs,autos') = unzip $ map (\(Automaton m) -> m a) autos in
core-js/Automaton.js+159−116
@@ -1,178 +1,221 @@
1+
2+(function() {
3+try{
4+
5+var $op={};
6+for(this['i'] in Elm){eval('var '+this['i']+'=Elm[this.i];');}
7+if (Elm.Automaton) throw "Module name collision, 'Automaton' is already defined.";
1Elm.Automaton=function(){
8Elm.Automaton=function(){
9+ try{
10+ if (!(Elm.Prelude instanceof Object)) throw 'module not found';
11+ } catch(e) {
12+ throw ("Module 'Prelude' is missing. Compile with --make flag or load missing module in a separate JavaScript file.");
13+ }
14+ var hiddenVars={};
2− for(this['i'] in Elm.Prelude){
15+ for (this['i'] in Elm.Prelude) {
16+ if (hiddenVars[this['i']]) continue;
3− eval('var ' + this['i'] + '=Elm.Prelude[this.i];'); }
17+ eval('var ' + this['i'] + ' = Elm.Prelude[this.i];');}
4 function Automaton_0(a1){
18 function Automaton_0(a1){
5− return ["Automaton",a1];};
19+ return ["Automaton",a1];}
6− var Listen_9=["Listen"];
20+ var Listen_8=["Listen"];
7− var Ignore_10=["Ignore"];
21+ var Ignore_9=["Ignore"];
8− function DragFrom_11(a1){
22+ function DragFrom_10(a1){
9− return ["DragFrom",a1];};
23+ return ["DragFrom",a1];}
10− var count_8=init_6(0)(function(__75){
24+ $op['>>>'] = function(a1_24){
11− return function(c_76){
12− return (1+c_76);};});
13− function run_1(Automaton$m0_15){
14− return function(input_16){
25+ return function(a2_25){
15 return function(){
26 return function(){
16− switch(Automaton$m0_15[0]){
17− case "Automaton":
18− return lift(fst)(foldp_(function(a_18){
19− return function(Tuple2$bAutomaton$m_19){
20− return function(){
21− switch(Tuple2$bAutomaton$m_19[0]){
22− case "Tuple2":
23− switch(Tuple2$bAutomaton$m_19[2][0]){
24− case "Automaton":
25− return Tuple2$bAutomaton$m_19[2][1](a_18);
26− }break;
27− }
28− throw "Non-exhaustive pattern match in case";}();};})(Automaton$m0_15[1])(input_16));
29− }
30− throw "Non-exhaustive pattern match in case";}();};};
31− function step_2(Automaton$m_22){
32− return function(a_23){
33− return function(){
34− switch(Automaton$m_22[0]){
35− case "Automaton":
36− return Automaton$m_22[1](a_23);
37− }
38− throw "Non-exhaustive pattern match in case";}();};};
39− function composeAuto_3(a1_25){
40− return function(a2_26){
41− return function(){
42− var Automaton$m1_27=a1_25;
27+ var Automaton$m1_26=a1_24;
43− var m1_28=function(){
28+ var m1_27=function(){
44− switch(Automaton$m1_27[0]){
29+ switch(Automaton$m1_26[0]){
45 case "Automaton":
30 case "Automaton":
46− return Automaton$m1_27[1];
31+ return Automaton$m1_26[1];
47 }
32 }
48 throw "Non-exhaustive pattern match in case";}();
33 throw "Non-exhaustive pattern match in case";}();
49− var Automaton$m2_29=a2_26;
34+ var Automaton$m2_28=a2_25;
50− var m2_30=function(){
35+ var m2_29=function(){
51− switch(Automaton$m2_29[0]){
36+ switch(Automaton$m2_28[0]){
52 case "Automaton":
37 case "Automaton":
53− return Automaton$m2_29[1];
38+ return Automaton$m2_28[1];
54 }
39 }
55 throw "Non-exhaustive pattern match in case";}();
40 throw "Non-exhaustive pattern match in case";}();
56− return Automaton_0(function(a_33){
41+ return Automaton_0(function(a_32){
57 return function(){
42 return function(){
58− var Tuple2$bm1__34=m1_28(a_33);
43+ var Tuple2$bm1__33=m1_27(a_32);
59− var b_35=function(){
44+ var b_34=function(){
60− switch(Tuple2$bm1__34[0]){
45+ switch(Tuple2$bm1__33[0]){
61 case "Tuple2":
46 case "Tuple2":
62− return Tuple2$bm1__34[1];
47+ return Tuple2$bm1__33[1];
63 }
48 }
64 throw "Non-exhaustive pattern match in case";}();
49 throw "Non-exhaustive pattern match in case";}();
65− var m1__36=function(){
50+ var m1__35=function(){
66− switch(Tuple2$bm1__34[0]){
51+ switch(Tuple2$bm1__33[0]){
67 case "Tuple2":
52 case "Tuple2":
68− return Tuple2$bm1__34[2];
53+ return Tuple2$bm1__33[2];
69 }
54 }
70 throw "Non-exhaustive pattern match in case";}();
55 throw "Non-exhaustive pattern match in case";}();
71 return function(){
56 return function(){
72− var Tuple2$cm2__41=m2_30(b_35);
57+ var Tuple2$cm2__40=m2_29(b_34);
73− var c_42=function(){
58+ var c_41=function(){
74− switch(Tuple2$cm2__41[0]){
59+ switch(Tuple2$cm2__40[0]){
75 case "Tuple2":
60 case "Tuple2":
76− return Tuple2$cm2__41[1];
61+ return Tuple2$cm2__40[1];
77 }
62 }
78 throw "Non-exhaustive pattern match in case";}();
63 throw "Non-exhaustive pattern match in case";}();
79− var m2__43=function(){
64+ var m2__42=function(){
80− switch(Tuple2$cm2__41[0]){
65+ switch(Tuple2$cm2__40[0]){
81 case "Tuple2":
66 case "Tuple2":
82− return Tuple2$cm2__41[2];
67+ return Tuple2$cm2__40[2];
83 }
68 }
84 throw "Non-exhaustive pattern match in case";}();
69 throw "Non-exhaustive pattern match in case";}();
85− return ["Tuple2",c_42,composeAuto_3(m1__36)(m2__43)];}();}();});}();};};
70+ return ["Tuple2",c_41,$op['>>>'](m1__35)(m2__42)];}();}();});}();};};
86− function combine_4(autos_48){
71+ $op['<<<'] = function(a2_47){
72+ return function(a1_48){
73+ return $op['>>>'](a1_48)(a2_47);};};
74+ $op['^>>'] = function(f_49){
75+ return function(a_50){
76+ return $op['>>>'](pure_4(f_49))(a_50);};};
77+ $op['>>^'] = function(a_51){
78+ return function(f_52){
79+ return $op['>>>'](a_51)(pure_4(f_52));};};
80+ $op['^<<'] = function(f_53){
81+ return function(a_54){
82+ return $op['>>>'](a_54)(pure_4(f_53));};};
83+ $op['<<^'] = function(a_55){
84+ return function(f_56){
85+ return $op['>>>'](pure_4(f_56))(a_55);};};
86+ var count_7=init_5(0)(function(__84){
87+ return function(c_85){
88+ return (1+c_85);};});
89+ function run_1(Automaton$m0_14){
90+ return function(input_15){
91+ return function(){
92+ switch(Automaton$m0_14[0]){
93+ case "Automaton":
94+ return lift(fst)(foldp_(function(a_17){
95+ return function(Tuple2$bAutomaton$m_18){
96+ return function(){
97+ switch(Tuple2$bAutomaton$m_18[0]){
98+ case "Tuple2":
99+ switch(Tuple2$bAutomaton$m_18[2][0]){
100+ case "Automaton":
101+ return Tuple2$bAutomaton$m_18[2][1](a_17);
102+ }break;
103+ }
104+ throw "Non-exhaustive pattern match in case";}();};})(Automaton$m0_14[1])(input_15));
105+ }
106+ throw "Non-exhaustive pattern match in case";}();};}
107+ function step_2(Automaton$m_21){
108+ return function(a_22){
109+ return function(){
110+ switch(Automaton$m_21[0]){
111+ case "Automaton":
112+ return Automaton$m_21[1](a_22);
113+ }
114+ throw "Non-exhaustive pattern match in case";}();};}
115+ function combine_3(autos_57){
87− return Automaton_0(function(a_49){
116+ return Automaton_0(function(a_58){
88 return function(){
117 return function(){
89− var Tuple2$bsautos__50=unzip(map(function(Automaton$m_53){
118+ var Tuple2$bsautos__59=unzip(map(function(Automaton$m_62){
90 return function(){
119 return function(){
91− switch(Automaton$m_53[0]){
120+ switch(Automaton$m_62[0]){
92 case "Automaton":
121 case "Automaton":
93− return Automaton$m_53[1](a_49);
122+ return Automaton$m_62[1](a_58);
94 }
123 }
95− throw "Non-exhaustive pattern match in case";}();})(autos_48));
124+ throw "Non-exhaustive pattern match in case";}();})(autos_57));
96− var bs_51=function(){
125+ var bs_60=function(){
97− switch(Tuple2$bsautos__50[0]){
126+ switch(Tuple2$bsautos__59[0]){
98 case "Tuple2":
127 case "Tuple2":
99− return Tuple2$bsautos__50[1];
128+ return Tuple2$bsautos__59[1];
100 }
129 }
101 throw "Non-exhaustive pattern match in case";}();
130 throw "Non-exhaustive pattern match in case";}();
102− var autos__52=function(){
131+ var autos__61=function(){
103− switch(Tuple2$bsautos__50[0]){
132+ switch(Tuple2$bsautos__59[0]){
104 case "Tuple2":
133 case "Tuple2":
105− return Tuple2$bsautos__50[2];
134+ return Tuple2$bsautos__59[2];
106 }
135 }
107 throw "Non-exhaustive pattern match in case";}();
136 throw "Non-exhaustive pattern match in case";}();
108− return ["Tuple2",bs_51,combine_4(autos__52)];}();});};
137+ return ["Tuple2",bs_60,combine_3(autos__61)];}();});}
109− function pure_5(f_59){
138+ function pure_4(f_68){
110− return Automaton_0(function(x_60){
139+ return Automaton_0(function(x_69){
111− return ["Tuple2",f_59(x_60),pure_5(f_59)];});};
140+ return ["Tuple2",f_68(x_69),pure_4(f_68)];});}
112− function init_6(s_61){
141+ function init_5(s_70){
113− return function(step_62){
142+ return function(step_71){
114− return Automaton_0(function(a_63){
143+ return Automaton_0(function(a_72){
115 return function(){
144 return function(){
116− var s__64=step_62(a_63)(s_61);
145+ var s__73=step_71(a_72)(s_70);
117− return ["Tuple2",s__64,init_6(s__64)(step_62)];}();});};};
146+ return ["Tuple2",s__73,init_5(s__73)(step_71)];}();});};}
118− function init__7(s_65){
147+ function init__6(s_74){
119− return function(step_66){
148+ return function(step_75){
120− return Automaton_0(function(a_67){
149+ return Automaton_0(function(a_76){
121 return function(){
150 return function(){
122− var Tuple2$bs__68=step_66(a_67)(s_65);
151+ var Tuple2$bs__77=step_75(a_76)(s_74);
123− var b_69=function(){
152+ var b_78=function(){
124− switch(Tuple2$bs__68[0]){
153+ switch(Tuple2$bs__77[0]){
125 case "Tuple2":
154 case "Tuple2":
126− return Tuple2$bs__68[1];
155+ return Tuple2$bs__77[1];
127 }
156 }
128 throw "Non-exhaustive pattern match in case";}();
157 throw "Non-exhaustive pattern match in case";}();
129− var s__70=function(){
158+ var s__79=function(){
130− switch(Tuple2$bs__68[0]){
159+ switch(Tuple2$bs__77[0]){
131 case "Tuple2":
160 case "Tuple2":
132− return Tuple2$bs__68[2];
161+ return Tuple2$bs__77[2];
133 }
162 }
134 throw "Non-exhaustive pattern match in case";}();
163 throw "Non-exhaustive pattern match in case";}();
135− return ["Tuple2",b_69,init__7(s__70)(step_66)];}();});};};
164+ return ["Tuple2",b_78,init__6(s__79)(step_75)];}();});};}
136− function vecSub_12(Tuple2$x1y1_77){
165+ function vecSub_11(Tuple2$x1y1_86){
137− return function(Tuple2$x2y2_78){
166+ return function(Tuple2$x2y2_87){
138 return function(){
167 return function(){
139− switch(Tuple2$x1y1_77[0]){
168+ switch(Tuple2$x1y1_86[0]){
140 case "Tuple2":
169 case "Tuple2":
141 return function(){
170 return function(){
142− switch(Tuple2$x2y2_78[0]){
171+ switch(Tuple2$x2y2_87[0]){
143 case "Tuple2":
172 case "Tuple2":
144− return ["Tuple2",(Tuple2$x1y1_77[1]-Tuple2$x2y2_78[1]),(Tuple2$x1y1_77[2]-Tuple2$x2y2_78[2])];
173+ return ["Tuple2",(Tuple2$x1y1_86[1]-Tuple2$x2y2_87[1]),(Tuple2$x1y1_86[2]-Tuple2$x2y2_87[2])];
145 }
174 }
146 throw "Non-exhaustive pattern match in case";}();
175 throw "Non-exhaustive pattern match in case";}();
147 }
176 }
148− throw "Non-exhaustive pattern match in case";}();};};
177+ throw "Non-exhaustive pattern match in case";}();};}
149− function stepDrag_13(Tuple2$presspos_83){
178+ function stepDrag_12(Tuple2$presspos_92){
150− return function(Tuple2$dsform_84){
179+ return function(Tuple2$dsform_93){
151 return function(){
180 return function(){
152− switch(Tuple2$presspos_83[0]){
181+ switch(Tuple2$presspos_92[0]){
153 case "Tuple2":
182 case "Tuple2":
154 return function(){
183 return function(){
155− switch(Tuple2$dsform_84[0]){
184+ switch(Tuple2$dsform_93[0]){
156 case "Tuple2":
185 case "Tuple2":
157 return function(){
186 return function(){
158− function wrap_89(ds__90){
187+ function wrap_98(ds__99){
159− return ["Tuple2",Tuple2$dsform_84[2],["Tuple2",ds__90,Tuple2$dsform_84[2]]];};
188+ return ["Tuple2",Tuple2$dsform_93[2],["Tuple2",ds__99,Tuple2$dsform_93[2]]];}
160 return function(){
189 return function(){
161− switch(Tuple2$dsform_84[1][0]){
190+ switch(Tuple2$dsform_93[1][0]){
162 case "DragFrom":
191 case "DragFrom":
163− return (Tuple2$presspos_83[1]?["Tuple2",uncurry(move)(vecSub_12(Tuple2$presspos_83[2])(Tuple2$dsform_84[1][1]))(Tuple2$dsform_84[2]),["Tuple2",DragFrom_11(Tuple2$dsform_84[1][1]),Tuple2$dsform_84[2]]]:function(){
192+ return (Tuple2$presspos_92[1]?["Tuple2",uncurry(move)(vecSub_11(Tuple2$presspos_92[2])(Tuple2$dsform_93[1][1]))(Tuple2$dsform_93[2]),["Tuple2",DragFrom_10(Tuple2$dsform_93[1][1]),Tuple2$dsform_93[2]]]:function(){
164− var form__92=uncurry(move)(vecSub_12(Tuple2$presspos_83[2])(Tuple2$dsform_84[1][1]))(Tuple2$dsform_84[2]);
193+ var form__101=uncurry(move)(vecSub_11(Tuple2$presspos_92[2])(Tuple2$dsform_93[1][1]))(Tuple2$dsform_93[2]);
165− return ["Tuple2",form__92,["Tuple2",Listen_9,form__92]];}());
194+ return ["Tuple2",form__101,["Tuple2",Listen_8,form__101]];}());
166 case "Ignore":
195 case "Ignore":
167− return wrap_89((Tuple2$presspos_83[1]?Ignore_10:Listen_9));
196+ return wrap_98((Tuple2$presspos_92[1]?Ignore_9:Listen_8));
168 case "Listen":
197 case "Listen":
169− return wrap_89((not(Tuple2$presspos_83[1])?Listen_9:(isWithin(Tuple2$presspos_83[2])(Tuple2$dsform_84[2])?DragFrom_11(Tuple2$presspos_83[2]):Ignore_10)));
198+ return wrap_98((not(Tuple2$presspos_92[1])?Listen_8:(isWithin(Tuple2$presspos_92[2])(Tuple2$dsform_93[2])?DragFrom_10(Tuple2$presspos_92[2]):Ignore_9)));
170 }
199 }
171 throw "Non-exhaustive pattern match in case";}();}();
200 throw "Non-exhaustive pattern match in case";}();}();
172 }
201 }
173 throw "Non-exhaustive pattern match in case";}();
202 throw "Non-exhaustive pattern match in case";}();
174 }
203 }
175− throw "Non-exhaustive pattern match in case";}();};};
204+ throw "Non-exhaustive pattern match in case";}();};}
176− function draggable_14(form_93){
205+ function draggable_13(form_102){
177− return init__7(["Tuple2",Listen_9,form_93])(stepDrag_13);};
206+ return init__6(["Tuple2",Listen_8,form_102])(stepDrag_12);}
178− return {Automaton:Automaton_0,run:run_1,step:step_2,composeAuto:composeAuto_3,combine:combine_4,pure:pure_5,init:init_6,init_:init__7,count:count_8,Listen:Listen_9,Ignore:Ignore_10,DragFrom:DragFrom_11,vecSub:vecSub_12,stepDrag:stepDrag_13,draggable:draggable_14};}();
207+ return {$op : {'>>>' : $op['>>>'], '<<<' : $op['<<<'], '^>>' : $op['^>>'], '>>^' : $op['>>^'], '^<<' : $op['^<<'], '<<^' : $op['<<^']},
208+ run:run_1,
209+ step:step_2,
210+ combine:combine_3,
211+ pure:pure_4,
212+ init:init_5,
213+ init_:init__6,
214+ count:count_7,
215+ draggable:draggable_13};}();
216+Elm.main=function(){
217+ return Elm.Automaton.main;};
218+} catch (e) {
219+Elm.main=function() {
220+var msg = ('<br/><h2>Your browser may not be supported. Are you using a modern browser?</h2>' + '<br/><span style="color:grey">Runtime Error in Automaton module:<br/>' + e + '</span>');
221+document.body.innerHTML = Elm.Text.monospace(msg);throw e;};}}());