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

1.) Rewrite prob1 so that it uses >>= instead of “do” notation. Please use >>= ,

ID: 3726455 • Letter: 1

Question

1.) Rewrite prob1 so that it uses >>= instead of “do” notation. Please use >>= , not >>
2.) Rewrite prob2 so it uses “do” notation
3.) Modify prob3 so it does the same computations as prob2, except with explicit state-passing
module Basics where import Control.Monad.State.Lazy probl:: 1o [integer] probl = do putStrin "probl" return [1,2,3] prob2 : State Integer Integer prob2 = get >>= ( x-> put (x + x) >> return 1) type sta s a = s-> (sa) prob3 : Sta Integer Integer prob3 s (ss)--fill this in reverseArgs : 10 [String] revers eArgs = return [] getFirstArgif: IO (Maybe String) getFirstArgf = return Nothing -(Unix) Basics.hs All L16SVN-29479-(Haskell1nteractive lnd) Welcame to GNU Emacs, a part of the GNU operating system.

Explanation / Answer

Step 1:

We need to replace Do as in Haskell it may be considred as harmful

Step 2

We can replace this code

do

putStrLn "probl"

return [1,2,3]

with

putStrLn "probl" >>= return [1,2,3]

Step 3:

The program would now read as:

module Basics where
import Control.Monad.State.Lazy
probl :: IO [Integer] probl =

putStrLn "probl" >>= return [1,2,3]
prob2 :: State Integer Integer
prob2 =
get >>= (x->
put (x + x) >>
return 1)

type Sta s a = s -> (s,a)
prob3 :: Sta Integer Integer
prob3 s = (s,s) - fill this in
reverseArgs IO [String]
reverseArgs = return[]
getFirstArglf IO (Maybe String)
qetFirstArglf = return Nothing