Skip to content

Latest commit

 

History

History
129 lines (104 loc) · 1.77 KB

ch03.adoc

File metadata and controls

129 lines (104 loc) · 1.77 KB

3 String

3.3 Printing simple things

Intermission: Exercises

all in scope

  1. y in scope for z

  2. h is not in scope for g

  3. cannot be laoded with error: Not in scope: ‘d’

  4. r and p are in scope for area

3.4 Type sigmatures of concatenation functions

fix errors

++ [1, 2, 3] [4, 5, 6]
-- fix
(++) [1, 2, 3] [4, 5, 6]

'<3' ++ ' Haskell'
--fix
"<3" ++ " Haskell"

concat ["<3", " Haskell"]
-- working

3.5 Concatenation and scoping

Print3Broken can be fixed simply by moving greeting = "Yarrrrr" to top level.

3.7 Chapter Exercises

Readinx syntax

fix errors

concat [[1, 2, 3], [4, 5, 6]]
-- working

++ [1, 2, 3] [4, 5, 6]
-- fix
(++) [1, 2, 3] [4, 5, 6]

(++) "hello" " world"
-- working

["hello" ++ " world]
-- fix
["hello" ++ " world"]

4 !! "hello"
-- fix
"hello" !! 4

(!!) "hello" 4
-- working

take "4 lovely"
-- fix
take 4 "lovely"

take 3 "awesome"
-- working

pair code and results

-- a) - d)
concat [[1 * 6], [2 * 6], [3 * 6]]
[6,12,18]

-- b) - c)
"rain" ++ drop 2 "elbow"
"rainbow"

-- c) - e)
10 * head [1, 2, 3]
10

-- d) - a)
(take 3 "Julie") ++ (tail "yes")
"Jules"

-- e) - b)
concat [tail [1, 2, 3], tail [4, 5, 6], tail [7, 8, 9]]
[2,3,5,6,8,9]

Building functions

  1. list manipulations

    -- a)
    "Curry is awesome" ++ "!" == "Curry is awesome!"
    
    -- b)
    "Curry is awesome!" !! 4 == "y"
    
    -- c)
    drop 9 "Curry is awesome!" == "awesome!"
  2. same code in file

    link:ch03_3.7_1.hs[role=include]
  3. third letter

    link:ch03_3.7_2.hs[role=include]
  4. letter index

    link:ch03_3.7_2_1.hs[role=include]
  5. make reverse function using drop and take for a fixed input. this point includes point 6.

    link:ch03_3.7_3.hs[role=include]