-- Mon Jan 23 08:06:00 CST 2017
{-
The following is by Jon Saxton:
A Dozen, a Gross, and a Score,
plus three times the square root of four,
divided by seven,
plus five times eleven,
equals nine squared and not a bit more.
-}
dozen = 12
gross = 144
score = 20
poem = (dozen + gross + score + 3 * sqrt(4.0)) / 7.0 + 5*11 == 9^2 + 0.0
-- score = 21 -- Can't do this
-- score = score + 1 -- Nor this
doubler x = x + x
twoarg x y = x / y
inv = twoarg 1 -- Currying, more coming later
inv' n = twoarg 1 n
exampleList = [5,6,9,12]
ex2 :: [String]
ex2 = ["hello", "world"]
ex3 = ['h', 'e', 'l', 'l', 'o']
-- length gives # elements in the list
a = length ex4
ex4 :: [Integer]
ex4 = [1, 2, 3]
-- length (head ex2) -- pull off the first element, then get its length
ex5 = [ex2, ["abc", "def"], []] -- ok
-- ex5 = [ex2, ["abc", "def"], [], ex3] -- not ok
ex6 = [3, 7, 3, 7, 8, 9, 9, -4, 5]
{-
"head" not the same as "take 1"
but we can do (take 1 ex6) !! 0 to get the same result as head ex6
++ concatenates two lists
reverse will reverse a list
sum/product will add/multiply the elements
-}
myOwnFirstElement ls = (take 1 ls) !! 0
myElem i ls = if i>=0 then ls !! i else -(ls !! (-i))
myElem' i ls = if i>=0 then ls !! i else "negative index!" -- This works(!)
-- myElem2 i ls = if i>=0 then ls !! i else 'x' -- This doesn't
trip x = x + x + x
alttrip x = (doubler x) + x