Skip to content

Instantly share code, notes, and snippets.

@AyaMorisawa
AyaMorisawa / ILocale.ts
Last active October 23, 2015 10:33
JSON Locale definition
interface ILocale {
langCode: string;
langName: string;
groups: {
groupName: string,
translates: {
source: string,
translate: string
}[]
}[];
function markov<T>(findFirst: () => T[][], findNext: (previous: T) => T[][]): T[][] {
function chooseRandom<T>(xs: T[]): T {
return xs[Math.floor(Math.random() * xs.length)];
}
function last<T>(xs: T[]): T {
return xs[xs.length - 1];
}
var result: T[][] = [];
import Graphics.Element exposing (show)
import String exposing (repeat)
(*) : String -> Int -> String
(*) = flip repeat
main = show ("foo" * 4)
import Graphics.Element exposing (show)
import List exposing (product)
factorial n = product [1..n]
main = show <| factorial 10 -- 3628800
import Html exposing (..)
import Html.Attributes exposing (..)
main = div
[style [("font-size", "64px")]]
[text "Hello, world!"]
import Graphics.Element exposing (..)
s f g x = f x (g x)
k p q = p
i a = a
main : Element
main =
show (s k k "Hello, world!")
piyo = (f, x) -->
| f x => 1 + piyo f, f x
| _ => 0
/* piyo.js
var piyo = function(f) {
return function(x) {
return f(x) ? 1 + piyo(f)(f(x)) : 0;
};
};
S = (f) -> (g) -> (x) -> (f x) (g x)
K = (p) -> (q) -> p
I = (a) -> a
(((S K (S I)) K) 'Hello, world') console.log
Promise a
Maybe a = (a | Undefined)
Either a b = (a | b)
Tuple a b = [a, b]
@AyaMorisawa
AyaMorisawa / map.ls
Last active August 29, 2015 14:17
Map
# (a -> b) -> Promise a -> Promise b
map-promise = (f, promise) --> promise.then (x) -> new Promise (resolve) -> resolve f x
# (a -> b) -> Maybe a -> Maybe b
map-maybe = (f, maybe) -->
| maybe? => f maybe
| _ => null
# (a -> b) -> [a] -> [b]
map-list = (f, xs) --> [f x for x in xs]