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', s) 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 Mainbak00 where | |
import Stack | |
-- スタックから 2 つの要素を取り出して足し合わせる | |
sumTwoElem :: Num a => Stack a -> (a, Stack a) | |
sumTwoElem stack0 = let (x1, stack1) = pop stack0 | |
(x2, stack2) = pop stack1 | |
in (x1+x2, stack2) | |
-- スタックから 4 つの要素を取り出して足し合わせる |
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 Mainbak01_00 where | |
import Stack | |
comb :: (Stack a -> (a, Stack a)) | |
-> (Stack a -> (a, Stack a)) | |
-> Stack a -> (a, Stack a) | |
comb m n = \stack0 -> | |
let (_, stack1) = m stack0 | |
(x, stack2) = n stack1 | |
in (x, stack2) |
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 Mainbak01_01 where | |
import Stack | |
{- | |
comb :: Num a => | |
(Stack a -> (a, Stack a)) | |
-> (Stack a -> (a, Stack a)) | |
-> Stack a -> (a, Stack a) | |
comb m n = \stack0 -> | |
let (x1, stack1) = m stack0 |
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 Mainbak01 where | |
import Stack | |
comb :: (Stack a -> (a, Stack a)) | |
-> (a -> (Stack a -> (a, Stack a))) | |
-> Stack a -> (a, Stack a) | |
comb m n = \stack0 -> | |
let (x1, stack1) = m stack0 | |
(x2, stack2) = n x1 stack1 | |
in (x2, stack2) |
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 Mainbak03 where | |
import Stack | |
type StackOp a b = Stack a -> (b, Stack a) | |
-- comb :: StackOp a b -> (b -> StackOp a b) -> StackOp a b -- これは間違い | |
comb :: StackOp a b -> (b -> StackOp a c) -> StackOp a c | |
comb m n = \stack0 -> | |
let (x1, stack1) = m stack0 | |
(x2, stack2) = n x1 stack1 |
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 Mainbak05 where | |
import Stack | |
-- スタック操作型 | |
newtype StackOp a b = StackOp {run :: Stack a -> (b, Stack a)} | |
-- Monad を真似したクラス | |
class MyMonad m where | |
-- comb :: m a -> (a -> m a) -> m a -- これ間違い | |
comb :: m a -> (a -> m b) -> m 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 Stack(Stack, empty, pop, push, s) where | |
newtype Stack a = Stack [a] deriving Show | |
empty :: Stack a | |
empty = Stack [] | |
pop :: Stack a -> (a, Stack a) | |
pop (Stack (x:xs)) = (x, Stack xs) | |
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 | |
import Data.Maybe | |
selectionsort [] = [] | |
selectionsort xs = head swapped : (selectionsort $ tail swapped) | |
where swapped = swap 0 indexOfMin xs | |
indexOfMin = fromJust $ elemIndex (minimum xs) xs | |
-- リスト xs のインデックス i, j の要素を交換 | |
swap i j xs | i < j = slice 0 (i-1) xs ++ [xs!!j] ++ |
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.Comparator; | |
import java.util.List; | |
import java.util.Arrays; | |
import java.util.Collections; | |
public class Person implements Comparable<Person> { | |
private String name; | |
private int age; |
OlderNewer