This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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") + ">" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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, "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Maybe | |
import Data.Unique | |
data Person = Person { oid :: Unique | |
, name :: String | |
, partner :: Partner | |
} | |
-- パートナー | |
type Partner = Maybe Person |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Person = Person { name :: String | |
, age :: Int | |
} deriving (Show, Read) | |
-- 年齢を標準入力から読み取る | |
readAge = readLn :: IO Int | |
-- 人の年齢を x 加算する | |
plusAge x (Person n a) = Person n (a+x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Node<T> { | |
private T a; | |
private Node next; | |
public Node(T a) { | |
this.a = a; | |
} | |
// 先頭に追加する |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IBinaryOp<A, B> { | |
public B apply(A a, B b); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Box<A> { | |
private A contents; | |
Box(A contents) { | |
this.contents = contents; | |
} | |
/** | |
* 中身を取り出す |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |