Instantly share code, notes, and snippets.

# じゅーとjutememo

• Sort options
Created Oct 14, 2009
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 [])
Created Oct 14, 2009
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 つの要素を取り出して足し合わせる
Created Oct 14, 2009
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)
Created Oct 14, 2009
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
Created Oct 14, 2009
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)
Created Oct 14, 2009
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
Created Oct 14, 2009
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
Created Oct 14, 2009
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)
Created Oct 19, 2009
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] ++
Created Oct 30, 2009
View Person.java
 import java.util.Comparator; import java.util.List; import java.util.Arrays; import java.util.Collections; public class Person implements Comparable { private String name; private int age;
You can’t perform that action at this time.