Last login: Wed Feb 27 12:12:15 on ttys009 : ~ ; exec /Users/dmason/fs/Courses/cps506/Lectures/Haskell/ghci.sh GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling March01 ( lecture.hs, interpreted ) Ok, modules loaded: March01. *March01> let a = 7 *March01> :t a a :: Num a => a *March01> let f () = a *March01> f() 7 *March01> :t f() f() :: Num a => a *March01> let f x = a + x *March01> :t f f :: Num a => a -> a *March01> f 5 12 *March01> let a = 37 *March01> f 5 12 *March01> f 3.14 10.14 *March01> let g x y = (x+1,y+1.5) *March01> :t g g :: (Fractional t1, Num t) => t -> t1 -> (t, t1) *March01> let h x y z = [(x y),head z] *March01> let h x y z = [x y,head z] *March01> *March01> :t h h :: (t1 -> t) -> t1 -> [t] -> [t] *March01> let i x y z = map (map x) (y z) *March01> :t map map :: (a -> b) -> [a] -> [b] *March01> :t i i :: (a -> b) -> (t -> [[a]]) -> t -> [[b]] *March01> :h [ help on the ghci interactive commands ] *March01> :browse Prelude [ a listing of many functions, modules, and type classes ] *March01> let j x y z = (x<=y,x==z) *March01> :t j j :: Ord a => a -> a -> a -> (Bool, Bool) *March01> let j x y z w = (x<=y,w==z) *March01> :t j j :: (Eq a1, Ord a) => a -> a -> a1 -> a1 -> (Bool, Bool) *March01> let f x y = x - y *March01> :e [1 of 1] Compiling March01 ( lecture.hs, interpreted ) Ok, modules loaded: March01. *March01> :t f :1:1: Not in scope: ‘f’ *March01> let f x y = x - y *March01> let l = [1,2,3,4] *March01> :t map f l map f l :: Num a => [a -> a] *March01> let g x f = f x *March01> length (map f l) 4 *March01> map (g 4) (map f l) [-3,-2,-1,0] *March01> map (g 45) (map f l) [-44,-43,-42,-41] *March01> map (g 45) (map f [3,4,5]) [-42,-41,-40] *March01> :t (+) (+) :: Num a => a -> a -> a *March01> map (3+) [1,2,3] [4,5,6] *March01> :info (+) class Num a where (+) :: a -> a -> a ... -- Defined in ‘GHC.Num’ infixl 6 + *March01> 3`f`4 -1 *March01> let second x = head (tail x) *March01> second [4,5,6] 5 *March01> let second x = head $ tail x *March01> second [4,5,6] 5 *March01> :info ($) ($) :: (a -> b) -> a -> b -- Defined in ‘GHC.Base’ infixr 0 $ *March01> :info (.) (.) :: (b -> c) -> (a -> b) -> a -> c -- Defined in ‘GHC.Base’ infixr 9 . *March01> let d f g x = g(f(x)) *March01> :t d d :: (t2 -> t1) -> (t1 -> t) -> t2 -> t *March01> let d f g x = f(g(x)) *March01> :t d d :: (t1 -> t) -> (t2 -> t1) -> t2 -> t *March01> let second = head . tail *March01> second [4,5,6] 5 *March01> map (g 4) . map f $ l [-3,-2,-1,0] *March01> map ($ 4) . map f $ l [-3,-2,-1,0] *March01> let third x = head ( tail (tail x)) *March01> let third x = head $ tail $ tail x *March01> map third ["asdf", "qwer", "zxcvvv"] "dec" *March01> map (\x -> head $ tail $ tail x) ["asdf", "qwer", "zxcvvv"] "dec" *March01> map (head . tail . tail) ["asdf", "qwer", "zxcvvv"] "dec" *March01>