Skip to content

Instantly share code, notes, and snippets.

じゅーと jutememo

Block or report user

Report or block jutememo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View mainbak01_00.hs
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)
View mainbak01_01.hs
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
View mainbak03.hs
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
View stack.hs
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)
View stack.hs
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 [])
View mainbak00.hs
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 つの要素を取り出して足し合わせる
View mainbak01.hs
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)
View mainbak05.hs
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
View selectionsort.hs
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] ++
View Person.java
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;
You can’t perform that action at this time.