This repository has been archived by the owner on Mar 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jshaskell-Haskell-min.js
30 lines (25 loc) · 9.03 KB
/
jshaskell-Haskell-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
JSHaskell - Some Haskell language features for JavaScript
http://code.google.com/p/jshaskell/
Copyright (c) 2010 Balazs Endresz ([email protected])
Dual licensed under the MIT and GPL licenses.
------------------------------------------------------------
*/
(function(){(function(){function s(a,b){return F[a]=b||{}}function ea(a,b){for(var c=F[a],d=0,e=b.length;d<e;++d){var f=F[a+"_"+b[d]];for(var g in f)c[g]=f[g]}}function fa(a){return ga.call(a)=="[object Array]"}function G(a){return a!==A}function ha(a,b){return a===b}function ia(a,b){return a!==b}function ja(a,b){return a+b}function ka(a,b){return a-b}function la(a,b){return a*b}function ma(a,b){return a/b}function na(a,b){return a<b}function oa(a,b){return a<=b}function pa(a,b){return a>b}function qa(a,
b){return a>=b}function ra(a){return-a}function B(a){var b=a.constructor;if(b)return b;a=typeof a;return a=="string"?String:a=="number"?Number:a=="boolean"?Boolean:a=="function"?Function:A}function sa(a){function b(){var c=t(arguments);return c.length>=(a._length===A?a.length:a._length)?a.apply(null,c):function(){return b.apply(null,c.concat(t(arguments)))}}return b}function Q(a){var b=t(arguments,1);return function(){return a.apply(null,b)}}function ta(){function a(b){return!b?[]:[[b.name||b._name||
b,b.arguments]].concat(a(b.caller))}return a(arguments.callee.caller)}function p(a){var b=(a instanceof Function?a.name||a._name:null)||a||"Unspecified error from "+arguments.callee.caller.name+" <- "+arguments.callee.caller.caller.name,c=new Error(b);try{c.stackTrace=ta()}catch(d){}c.message=b;throw c;}function ua(a,b){for(var c in b)a[c]=b[c];return a}function H(a,b){if(b.indexOf)return b.indexOf(a);var c=b.length;if(!c)return-1;for(var d=0;d<c;d++)if(b[d]===a)return d;return-1}function R(a,b){if(b.lastIndexOf)return b.lastIndexOf(a);
var c=b.length;if(!c)return-1;for(c=c-1;c>-1;--c)if(b[c]===a)return c;return-1}function va(a){var b=a.charAt;a=S(a);a.sort();return b?a.join(""):a}function S(a){if(!a.charAt)return I.call(a,0);for(var b=[],c=0,d=a.length;c<d;++c)b.push(a.charAt(c));return b}function wa(a,b){return{indexOf:function(c){return c>=a&&c<=b?true:-1},toString:function(){return"range("+a+", "+b+")"}}}function xa(a,b){function c(){var d=100*b;do a=a();while(--d&&a&&a.call);setTimeout(c,1)}if(!b||b==Infinity){do a=a();while(a&&
a.call);return a}c()}function ya(a,b){return b?b[a]:function(c){return c[a]}}function T(){}function C(){}function U(a){return function(){var b=[],c=this._recordset;if(c&&c.constructor!=Array){for(var d in c){var e=a?c[d].name||c[d]:this[d];if(!a&&e instanceof Function)e=e.constructor!=Function?e.constructor.name:"Function("+e.name+")";b.push(d+(a?" :: ":" = ")+e)}c=replicate(this._dataConstructor.length+2," ").join("");b="{"+b.join("\n"+c+",")+"\n"+c+"}"}else{for(d=0;d in this;d++)b.push(a?c[d].name||
c[d]:this[d]);b=b.join(" ")}return"("+this._dataConstructor+(b?" ":"")+b+")"}}function V(a,b,c,d,e){p("Type error: expecting "+a.name+" instead of "+b.name+" in the argument '"+c+"' of "+d+"."+e)}function za(a,b){function c(h,k){function x(Aa,W){var o=Aa instanceof T,l=new a,y,q;l.constructor=a;l._recordset=j&&k[0]||k;l._dataConstructor=h;l[h]=true;if(o)for(var m in W){o=W[m];j||p("Records are not defined for "+d+"."+h);m in n||p("The accessor '"+m+"' is not defined for "+d+"."+h);q=n[m];if(typeof q!=
"string"){y=B(o);y!=q&&V(q,y,m,d,h)}l[m]=o;l[X[m]]=o}else{m=arguments;for(var u=0,Ba=m.length;u<Ba;++u){o=m[u];q=k[u];if(typeof q!="string"){y=B(o);y!=q&&V(q,y,u,d,h)}l[u]=o;if(j)l[Y[u]]=o}}l.update=function(Z){var $={};for(var E in n)$[E]=E in Z?Z[E]:this[E];return x(aa,$)};return l}var j=k&&typeof k[0]=="object",n=j&&k[0];if(j){var J=0,v,X={},Y={};for(v in n){var K=v.charAt(0);if(K=="_"||K==K.toUpperCase())throw d+"."+i+"."+v+": record names can't start with underscore or uppercase letters";if(v in
{update:1})throw d+"."+i+"."+v+": record name is invalid";X[v]=J;Y[J]=v;J++}}return x}var d=a.name;if(a._constructors)throw"Type constructor has been already defined: '"+d+"'";a._constructors=b;a.prototype=new C;for(var e=0,f=b.length;e<f;++e){var g=typeof b[e]!="object",i=g?b[e]:b[e][0];if(i in a)throw"The name of the data constructor ("+d+"."+i+") is invalid!";a[i]=g?c(i)():c(i,t(b[e],1));if(!g)a[i]._length=b[e].length-1}}function Ca(a){return a._dataConstructor}function L(){this.keys=[];this.values=
[]}function Da(a,b){var c={};c._context=[];c._name=a;c._dict=new L;c.context=function(){this._context=t(arguments);delete c.context;return this};c.types=function(d){this._fnTypes=d;delete c.types;return this};c.impl=function(d){this._default=d;for(var e in c._fnTypes)(function(f,g){c[f]=g!==A&&g.constructor!=Array?(typeof d=="function"?d():d)[f]:function(){var i=arguments,h;if(g===A||g===M)p("There's no type signature for "+c._name+"."+f+", it can be accessed only by: getInstance("+c._name+", SomeType)."+
f);var k,x=N(function(j,n){n=g[n];if(k||n==M)return k=true;j=B(j);if(n==b){h=h||j;return h==j}else return j==n},i);!k&&x.length!=g.length-1&&p("Type error in "+c._name+"."+f);(x=c._dict.get(h))||p("No "+c._name+" instance for "+(h.name||h._name));return x[f].apply(null,i)}})(e,c._fnTypes[e]);delete c.impl;return this};return c}function Ea(a,b,c){z(function(g){if(!g._dict.get(b))throw"No "+(g._name||"")+" instance for "+(b.name||b._name);},a._context);var d={};d._type=b;a._dict.put(b,d);c=typeof c==
"function"?c(d):c||{};var e=a._default;e=typeof e=="function"?e(d):e;for(var f in a._fnTypes)d[f]=c[f]||e[f];return d}function Fa(a,b){return a._dict.get(b)}function Ga(a,b,c){return a._dict.get(B(c))[b]}function Ha(a){return["l",a]}function Ia(a){return["r",a]}function Ja(a){return["x",a]}function Ka(a){if(a)if(!a._String){var b=D[a];if(a._Op&&!b)return"l";return b&&(b.fixity[0]||"l")}}function La(a){if(a)if(!a._String){var b=D[a];if(a._Op&&!b)return 9;return b&&(G(b.fixity[1])?b.fixity[1]:9)}}function O(){}
function P(a,b,c){var d;if(a[b]._Op){delete a[b]._Op;d=a[b]}else d=D[a[b]].func;d=d(a[b-1],a[b+1]);a.splice(b-1,3,d);return w(a,c)}function Ma(a){if(typeof a=="string"){a=new String(a);a._String=true;return a}else{a._Array=true;return a}}function Na(a){a._Op=true;return a}function w(a,b){a=z(function(h){if(!h)return h;if(h._Array){delete h._Array;return h}return h.constructor==Array?w(h,b):h.CallStream?h.resolve(b):h},a);if(b)a=z(function(h){return h instanceof O?b:h},a);for(var c=[],d=[],e=0,f=a.length;e<
f;++e){var g=a[e],i=false;if(D[g])i=true;if(g&&g._String){i=false;g=g.toString()}if(g&&g._Op)i=true;if(!i&&e!=f-1)c.push(g);else{e==f-1&&c.push(g);c=c.length>1?c[0].apply(null,c.slice(1)):c[0];d.push(c);e!=f-1&&d.push(g);c=[]}}a=d;d=z(Ka,a);f=z(La,a);g=N(G,f).sort().pop();e=H(g,f);f=R(g,f);return d[e]=="l"?P(a,e,b):d[f]=="r"?P(a,f,b):d[e]=="x"?P(a,e,b):a[0]}function Oa(a){return function(){function b(){return e.apply(null,arguments)}function c(){return(f?e:c.resolve()).apply(null,arguments)}var d=
arguments,e,f;c.resolve=function(g){if(f)return e;e=w(d,g||b);d=null;f=true;return e};c.CallStream=true;c.constructor=a;return c}}function Pa(){return w(t(arguments))}function ba(a){this.scope=a}function Qa(a){return function(){function b(){return e.apply(null,arguments)}function c(g){if(f||g instanceof ba)return(f?e:c.resolve()).apply(null,arguments);d.push(w(arguments,b));return c}var d=[],e,f;d.push(w(arguments,b));c.resolve=function(){if(f)return e;e=a.do_.apply(null,d);f=true;d=null;return e};
c.CallStream=true;c.constructor=a._type;return c}}var r=function(){return this}()||window,F=r.NS||(r.NS={}),A,ga={}.toString,I=[].slice,ca=[].map,da=[].filter;(function(){return this}).toString().indexOf("this");(function(){var a={9:1,d:1,b:1,0:1,a:1,c:1},b=[9,"d","b",0,"a","c"],c=0;for(var d in a)if(d!=b[c++])return false;return true})();r.global=r;r.namespace=s;r.importSubmodules=ea;var t="a"[0]?function(a,b){return I.call(a,b||0)}:function(a,b){if(typeof a=="string"){a=a.split("");if(!b)return a}return I.call(a,
b||0)},z=ca?function(a,b){return ca.call(b,a)}:function(a,b){for(var c=[],d=0,e=b.length;d<e;++d)c[d]=a(b[d],d,b);return c},N=da?function(a,b){return da.call(b,a)}:function(a,b){for(var c=[],d=0,e=b.length;d<e;++d)a(b[d],d,b)&&c.push(b[d]);return c};s("Haskell_Main",{Bool:Boolean,isArray:fa,isDefined:G,slice:t,imap:z,ifilter:N,indexOf:H,lastIndexOf:R,isort:va,range:wa,extend:ua,namespace:s,typeOf:B,strictEq:ha,strictNe:ia,unsafeAdd:ja,unsafeSub:ka,unsafeMul:la,unsafeDiv:ma,lt:na,le:oa,gt:pa,ge:qa,
negate:ra,evalThunks:xa,toArray:S,curry:sa,error:p,eta:Q});var aa=new T;C.prototype.toString=U();C.prototype.dataConstructorToString=U(true);C.prototype.update=Q(p);s("Haskell_DataType",{data:za,ADT:C,record:aa,accessor:ya,accessors:{},showConstrOf:Ca});L.prototype.put=function(a,b){this.keys.push(a);this.values.push(b)};L.prototype.get=function(a){a=H(a,this.keys);if(a!=-1)return this.values[a]};var M={};s("Haskell_TypeClass",{typeclass:Da,VARARG:M,instance:Ea,getInstance:Fa,asTypeOf:Ga});var D=
{};r=new O;s("Haskell_Expression",{operators:D,infix:Ja,infixl:Ha,infixr:Ia,op:Na,no:Ma,resolve:w,recurse:r,Recurse:O,exl:Oa,exs:Pa});s("Haskell_Do",{createDo:Qa,Scope:ba})})();(function(){namespace("Haskell");importSubmodules("Haskell",["Main","DataType","TypeClass","Expression","Do"])})()})();