りすと
- リスト
- になる
これは
- リストに
- なる
(* Utilities *) | |
let (|>) x f = f x | |
let (|-) f g = fun x -> g (f x) | |
let getOrElse defVal = function | |
| Some(v) -> v | |
| None -> defVal | |
(* Term Definition *) | |
type term = | |
| TmVar of int * int (* 変数 : deBruijn_index * term_length *) |
りすと
これは
fn main() { | |
repeat_cps(10, "hello", Box::new(|r| { | |
println!("{:?}", r) | |
})) | |
} | |
fn repeat_cps<'a, A, B>(n: i32, x: A, k: Box<Fn(A) -> B + 'a>) -> B | |
{ | |
if n == 0 { | |
k(x) |
fn main() { | |
println!("{:?}", take_while(&[1, 2, 3, 4, 5], |&x| x < 3)); | |
} | |
fn take_while<T, F>(xs: &[T], f: F) -> &[T] | |
where F: Fn(&T) -> bool | |
{ | |
let mut i = 0; | |
while f(&xs[i]) { | |
i += 1; |
/* eslint no-console: "off", no-unused-vars: "off" */ | |
var xs = [ | |
{id: 'A', pid: '', name: 'aaa'}, | |
{id: 'B', pid: '', name: 'bbb'}, | |
{id: 'C', pid: '', name: 'ccc'}, | |
{id: 'A-a', pid: 'A', name: 'aaa-aaa'}, | |
{id: 'A-b', pid: 'A', name: 'aaa-bbb'}, | |
{id: 'B-a', pid: 'B', name: 'bbb-aaa'}, | |
{id: 'B-b', pid: 'B', name: 'bbb-bbb'}, | |
{id: 'C-a', pid: 'C', name: 'ccc-aaa'}, |
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-} | |
import Data.Ratio | |
class (Num a) => Dividable a where | |
divide :: a -> a -> a | |
instance {-# INCOHERENT #-} (Integral a) => Dividable a where | |
divide = div | |
instance Dividable Double where |
import Data.String | |
import Control.Monad | |
import Data.Maybe | |
main :: IO () | |
main = interactEachLines $ (fromMaybe "Error!") . rpn | |
interactEachLines :: (String -> String) -> IO () | |
interactEachLines f = interact $ unlines . (map f) . lines |
let s:V = vital#of('vital') | |
function! s:truncate(text, max_width, ellipsis) | |
let ellipsis_width = strdisplaywidth(a:ellipsis) | |
let text_width = strdisplaywidth(a:text) | |
if text_width > a:max_width | |
let truncated = s:V.strwidthpart(a:text, a:max_width - ellipsis_width) | |
" for double width string | |
if strdisplaywidth(truncated) != a:max_width - ellipsis_width | |
let truncated .= ' ' | |
endif |
import System.Environment | |
import System.Directory | |
import System.IO | |
import Data.List | |
import Control.Exception | |
dispatch :: String -> [String] -> IO () | |
dispatch "add" = add | |
dispatch "view" = view | |
dispatch "remove" = remove |
let s:V = vital#of('r') | |
let s:Xor = s:V.import('Random.Xor128') | |
function! s:randomString(char_kind, length) | |
let rand_str = '' | |
for i in range(a:length) | |
let rand_char = a:char_kind[abs(s:Xor.rand()) % len(a:char_kind)] | |
let rand_str .= rand_char | |
endfor | |
return rand_str |