Skip to content

Instantly share code, notes, and snippets.

@totem3
Created February 5, 2012 13:38
Show Gist options
  • Save totem3/1745621 to your computer and use it in GitHub Desktop.
Save totem3/1745621 to your computer and use it in GitHub Desktop.
プログラミングHaskell第4章練習問題 むむむずい
--1
halve :: [a] -> ([a], [a])
halve xs = (take len xs, drop len xs)
where
len = fromIntegral (length xs) `div` 2
--2
-- if
safetail :: (Eq a) => [a] -> [a]
safetail xs = if xs == [] then [] else drop 1 xs
-- guard
safetail2 :: (Eq a) => [a] -> [a]
safetail2 xs | xs == [] = []
| otherwise = drop 1 xs
-- pattern
safetail3 :: [a] -> [a]
safetail3 [] = []
safetail3 xs = drop 1 xs
--3
-- if
orfunc :: Bool -> Bool -> Bool
orfunc a b = if a == False && b == False then False else True
-- guard
orfunc2 :: Bool -> Bool -> Bool
orfunc2 a b | a == False && b == False = False
| otherwise = True
-- pattern
orfunc3 :: Bool -> Bool -> Bool
orfunc3 False False = False
orfunc3 _ _ = True
--pattern2
orfunc4 :: Bool -> Bool -> Bool
orfunc4 True True = True
orfunc4 True False = True
orfunc4 False True = True
orfunc4 False False = False
--3
andfunc :: Bool -> Bool -> Bool
andfunc a b = if a == True then
if b == True then True else False
else False
--4
andfunc2 :: Bool -> Bool -> Bool
andfunc2 a b = if a == True then b else False
--5
-- (\x -> \y -> \z -> x * y * z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment