Put your program(s) in a *.hs file. Answers to written questions can be done as a big comment in your *.hs file, or you can include them in a separate file

 

 

1.

State monad values contain a function of type state → (value, state). We’re going to modify them so that functions return a Maybe(value, state) . I.e.,, we have

newtype Mstate state val = Mstate (state -> Maybe(val, state))

apply (Mstate f) = f

The apply function unwraps an Mstate value so to actually runan Mstate value v on a state s, you use apply v s. (The State monad uses runState; we’ve just renamed it is all.)

The file Maybe_State_skeleton.hs contains a skeleton of a file that holds the framework for making Maybe_State a monad. To complete it, you’ll need to fill in the bodies of the fmap, <*>, >>=, and <|> operations. You’ll want to run tests yourself as you write the code, but there are also some tests in Maybe_State_test.hs you can try.

Recommended approach: Write and test the functions one at a time, without the monadic framework. E.g., create a development file with just the import, newtype, and apply definitions and add an fmap function by itself, without any class type instances. (You may need to change the name from fmap to something else to avoid name clashes with the standard prelude). Once a function is complete, then try (renaming it to fmap and) fitting it into the appropriate class type instance.

Since Maybe is itself a monad, you can use the >>= operator on Maybe values to avoid having to write case splits to see “if … is Nothing then yield Nothing, else if it’s Just (a, s) then … “. (The <|> operator is an exception because it doesn’t follow the “Nothing yields Nothing” pattern.) Avoiding case splits (or functions with pattern matching) on Nothing or Just … (except for <|>) is worth 5 of the total points. (If you can’t figure out ho

 
******CLICK ORDER NOW BELOW TO GET THE ANSWER TO THIS ASSIGNMENT OR ANY OTHER ASSIGNMENT, DISCUSSION, ESSAY, HOMEWORK OR QUESTION*******."
Whatsapp us.