/ undefined ʹک͑Δඞཁͳ͍ let x = Some 2 let y = None let f = function | Some n -> n | None -> 0 (* default value *) var x = 2; var y = undefined; function f(param) { if (param !== undefined) { return param; } else { return 0; } }
ܞ ͕ ؆ ୯ ‣ JavaScript ͷόΠϯσΟϯά؆୯ʹͰ͖Δ external length: string -> int = "length" [@@bs.get] external substr: string -> int -> int -> string = "substr" [@@bs.send] let str = "ABCDE" let n = length str let sub = substr str 1 3 var str = "ABCDE"; var n = str.length; var sub = str.substr(1, 3);
‣ ൺֱత៉ྷͳ JavaScript (ES5) ͕ग़ྗ͞ΕΔ let x = Some 2 let y = None let f = function | Some n -> n | None -> 0 var x = 2; var y = undefined; function f(param) { if (param !== undefined) { return param; } else { return 0; } }
‣ ൺֱత៉ྷͳ JavaScript (ES5) ͕ग़ྗ͞ΕΔ let rec loop n = if n > 0 then begin Js.log n; loop (n - 1) end else () function loop(_n) { while(true) { var n = _n; if (n > 0) { console.log(n); _n = n - 1 | 0; continue ; } else { return /* () */0; } }; }
ຊޠͱ͔Λॻ͘ͱΊΜͲ͍͘͞ let wrong = "日本語" let ok = {js|日本語|js} (* j では変数の展開もできる *) let ok2 = {j|日本語|j} var wrong = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"; var ok = "日本語"; var ok2 = "日本語";