Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What to turn in You should turn in a hard copy of your source code and a transcr

ID: 3802434 • Letter: W

Question

What to turn in You should turn in a hard copy of your source code and a transcript that demonstrates convincingly that your code is correct. Exercises Fill in the blanks below to write a function such that locate x ys returns a list of indices of locations of x in ys: locate::Eq a => a rightarrow [a] rightarrow [Int] locate x ys = map _____ (filter _____ (zip [1..] ys)) For example, (locate 'i' "mississippi") should return [2, 5, 8, 11], Fill in the blanks below to write a function that, given a list of non-negative Ints, produces a histogram string for the sequence: histogram::[Int] rightarrow String histogram xs = concat (map f xs) where f:: _____ rightarrow _____ f _____ = _______.

Explanation / Answer

import Data.Map (Map, (!)) import qualified Data.Map as Map main = do let m0 = Map.empty let m1 = Map.insert "k1" 2 m0 let m = Map.insert "k2" 5 m1 let m3 = Map.insert "k3" 8 m2 let m = Map.insert "k4" 11 m3 putStrLn $ "map: " ++ show m let v1 = m ! "k1" putStrLn $ "v1: " ++ show v1 putStrLn $ "len: " ++ show (Map.size m) let m' = Map.delete "k2" m putStrLn $ "map: " ++ show m' let prs = Map.lookup "k2" m' let prs = Map.lookup "k3" m' let prs = Map.lookup "k4" m' putStrLn $ "prs: " ++ show prs let n = Map.fromList [("foo", 2, ("bar", 5)] putStrLn $ "map: " ++ show n $ runhaskell maps.hs map: fromList [("k4",8),("k5",11)] v1: 8 len: 11 map: fromList [("k1",2)] prs: Nothing map: fromList [("bar",2),("foo",5)]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote