Skip to content

Instantly share code, notes, and snippets.

module Control
def if(e1, e2)
if self.isTrue? then e1 else e2 end
end
def if_(e1, e2)
self.if(e1, e2).call
end
end
module Bool
# -*- coding: utf-8 -*-
class Person:
def __init__(self, name):
self.__name = name
self.__partner = None
def getName(self): return self.__name
def __str__(self):
return self.__name + "<" + (self.__partner.getName() if self.__partner else "None") + ">"
-- Monad の (>>=) に相当
comb m n = let (a, log1) = m
(b, log2) = n a
in (b, log1 ++ log2)
-- Monad の (>>) に相当
comb_ m n = m `comb` \x -> n
-- Monad の return に相当
ret x = (x, "")
import Data.Maybe
data Person = Person { name :: String
, partner :: Partner
} deriving Eq
-- パートナー
type Partner = Maybe Person
instance Show Person where
show (Person n Nothing) = n
import Data.Maybe
import Data.Unique
data Person = Person { oid :: Unique
, name :: String
, partner :: Partner
}
-- パートナー
type Partner = Maybe Person
data Person = Person { name :: String
, age :: Int
} deriving (Show, Read)
-- 年齢を標準入力から読み取る
readAge = readLn :: IO Int
-- 人の年齢を x 加算する
plusAge x (Person n a) = Person n (a+x)
public class Node<T> {
private T a;
private Node next;
public Node(T a) {
this.a = a;
}
// 先頭に追加する
public interface IBinaryOp<A, B> {
public B apply(A a, B b);
}
public class Box<A> {
private A contents;
Box(A contents) {
this.contents = contents;
}
/**
* 中身を取り出す
public class Main {
public static void main(String[] args) {
Box<Integer> box1 = new Box<Integer>(100);
System.out.println(box1.takeOut()); // 100
System.out.println(box1.takeOut(
new IBinaryOp<Integer, Integer>() {
public Integer apply(Integer a, Integer b) {
return a + b;