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 java.util.Arrays; | |
import java.util.List; | |
/** | |
* 検索クラス | |
*/ | |
public class Search { | |
private static List<Person> persons = Arrays.asList( | |
new Person("Tarou", "Tokyo"), |
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 java.util.Arrays; | |
import java.util.List; | |
/** | |
* 検索クラス | |
*/ | |
public class Search { | |
private static List<Person> persons = Arrays.asList( | |
new Person("Tarou", "Tokyo"), |
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 java.util.Arrays; | |
import java.util.List; | |
/** | |
* 検索クラス | |
*/ | |
public class Search { | |
private static List<Person> persons = Arrays.asList( | |
new Person("Tarou", "Tokyo"), |
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.List | |
data Person = Person { name, address :: String} deriving Show | |
ps = [ Person "Tarou" "Tokyo" | |
, Person "Jirou" "Osaka" | |
, Person "Saburou" "Nagoya" | |
] | |
getAddress n ps = case find ((== n) . name) ps of |
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 Counter where | |
-- カウンタを表わす型 | |
data Counter a = Counter { val -- 値 | |
, step :: a -- 増分 | |
} deriving Show | |
-- カウンタの値を増加させる | |
next :: Num a => Counter a -> (a, Counter a) | |
next (Counter v s) = let v' = v + s |
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 State (State, comb, comb_, ret) where | |
type State s a = s -> (a, s) | |
comb :: State s a -> (a -> State s b) -> State s b | |
comb m n = \s0 -> let (x1, s1) = m s0 | |
(x2, s2) = n x1 s1 | |
in (x2, s2) | |
comb_ :: State s a -> State s b -> State s 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
module Counter where | |
-- カウンタを表わす型 | |
data Counter a = Counter { val -- 値 | |
, step :: a -- 増分 | |
} deriving Show | |
-- カウンタの値を増加させる | |
next :: Num a => Counter a -> (a, Counter a) | |
next (Counter v s) = let v' = v + s |
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 Stack(Stack, empty, empty', pop, push, push') where | |
newtype Stack a = Stack [a] deriving Show | |
empty :: Stack a | |
empty = Stack [] | |
empty' :: Stack a -> ((), Stack a) | |
empty' _ = ((), Stack []) | |
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 Main where | |
import State | |
import Counter | |
import Stack | |
next3 = next `comb_` next `comb_` next | |
push3 = push' 100 `comb_` push' 200 `comb_` push' 300 | |
counter = Counter 0 1 | |
stack = push 5 $ push 4 $ push 3 $ push 2 $ push 1 empty |
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
class Boolean b where | |
isTrue :: b -> Bool | |
instance Boolean Bool where | |
isTrue True = True | |
isTrue False = False | |
instance Boolean Integer where | |
isTrue 0 = False | |
isTrue _ = True |