2009-12-03から1日間の記事一覧

RWH 4.5.6 リストの探索

myElem :: (Eq a) => a -> [a] -> Bool myElem _ [] = False myElem e (x:xs) | e == x = True | otherwise = myElem e xs myNotElem :: (Eq a) => a -> [a] -> Bool myNotElem e = not . myElem e myFilter :: (a -> Bool) -> [a] -> [a] myFilter _ [] = […

RWH 4.5.5 部分リストを使う

myTake :: Int -> [a] -> [a] myTake _ [] = [] myTake n (x:xs) | n > 0 = x : (myTake (n - 1) xs) | otherwise = [] myDrop :: Int -> [a] -> [a] myDrop _ [] = [] myDrop n (x:xs) | n > 0 = myDrop (n - 1) xs | otherwise = x:xs mySplitAt :: Int ->…