Skip to content

Instantly share code, notes, and snippets.

@ikedaisuke
Created November 30, 2012 11:54
Show Gist options
  • Save ikedaisuke/4175351 to your computer and use it in GitHub Desktop.
Save ikedaisuke/4175351 to your computer and use it in GitHub Desktop.
Some answers of the homework in the slides
-- http://koko-u.github.com/haskell_book_reading/#25
import Data.Char (toUpper, intToDigit, isSpace)
import Data.List (isInfixOf, nub)
import Numeric (showIntAtBase)
upperCase :: String -> String
upperCase = map toUpper
removeSpaces :: String -> String
removeSpaces = filter (not . isSpace)
-- cover almost equals isInfixOf
cover :: Eq a => [a] -> [a] -> Bool
cover = flip isInfixOf
uniq :: Eq a => [a] -> [a]
uniq = nub
-- http://stackoverflow.com/questions/1959715/how-to-print-integer-literals-in-binary-or-hex-in-haskell
binExp :: Int -> String
binExp x = showIntAtBase 2 intToDigit x ""
hanoi = undefined -- skip at the moment
fib :: Int -> Integer
fib n = fibs !! n
where fibs :: [Integer]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment