@@ -33,13 +33,14 @@ Elm.Native.Show = function(elm) {
34 var toString = function(v) {
34 var toString = function(v) {
35 if (typeof v === "function") {
35 if (typeof v === "function") {
36+ var name = v.func ? v.func.name : v.name;
36− return "<function>";
37+ return '<function' + (name === '' ? '' : ': ') + name + '>';
37 } else if (typeof v === "boolean") {
38 } else if (typeof v === "boolean") {
38 return v ? "True" : "False";
39 return v ? "True" : "False";
39 } else if (typeof v === "number") {
40 } else if (typeof v === "number") {
40 return v+"";
41 return v+"";
41 } else if (typeof v === "string" && v.length < 2) {
42 } else if (typeof v === "string" && v.length < 2) {
42− return "'"+v+"'";
43+ return "'" + showChar(v) + "'";
43 } else if (typeof v === "object" && '_' in v) {
44 } else if (typeof v === "object" && '_' in v) {
44 var output = [];
45 var output = [];
45 for (var k in v._) {
46 for (var k in v._) {
@@ -67,9 +68,7 @@ Elm.Native.Show = function(elm) {
67 start = isStr ? '"' : "[",
68 start = isStr ? '"' : "[",
68 end = isStr ? '"' : "]",
69 end = isStr ? '"' : "]",
69 sep = isStr ? "" : ",",
70 sep = isStr ? "" : ",",
70− f = !isStr ? toString : function(x){
71+ f = !isStr ? toString : showChar;
71− return x === '\n' ? '\\n' : x;
73 var output = start + f(v._0);
72 var output = start + f(v._0);
75 while (v.ctor === "Cons") {
74 while (v.ctor === "Cons") {
@@ -103,5 +102,17 @@ Elm.Native.Show = function(elm) {
104 function show(v) { return NList.fromArray(toString(v)); }
103 function show(v) { return NList.fromArray(toString(v)); }
105+ function showChar (c) {
106+ return c === '\n' ? '\\n' :
107+ c === '\t' ? '\\t' :
108+ c === '\b' ? '\\b' :
109+ c === '\r' ? '\\r' :
110+ c === '\v' ? '\\v' :
111+ c === '\0' ? '\\0' :
112+ c === '\'' ? "\\'" :
113+ c === '\"' ? '\\"' :
114+ c === '\\' ? '\\\\' : c;
106 return elm.Native.Show = { show:show };
117 return elm.Native.Show = { show:show };