On Github miami-acm / haskell-tutorial
something x = x + 1
something :: Int -> Int something x = x + 1
something :: Int -> Int something x | x > 0 = x + 1 | otherwise = x
something :: Int -> Int something 0 = 1 something x = x
something :: [Int] -> Bool something [] = True something x = False
isEmpty :: [a] -> Bool isEmpty [] = True isEmpty x = False
λ ghci func.hs GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( func.hs, interpreted ) Ok, modules loaded: Main. *Main> isEmpty [] True *Main> isEmpty [12, 13] False
> let addOne x = x + 1 > let apply x f = f x > apply 10 addOne 11
> let addOne x = x + 1 > let myNums = [0, 1, 2, 3, 4, 5] > map addOne myNums [1,2,3,4,5,6]
> let myNums = [0, 1, 2, 3, 4, 5] > map (\x -> x * 100) myNums [0,100,200,300,400,500]
max :: (Ord a) => [a] -> a max [] = error max [x] = x max (x:xs) | x > maxTail = x | otherwise = maxTail where maxTail = max xs
something :: (Ord a) => [a] -> [a] something [] = [] somthing (x:xs) = let f = something [a | a <- xs, a <= x] b = something [a | a <- xs, a > x] in f ++ [x] ++ b