Haskell Programming, computer science homework help

I need the following exercise’s completed in the programming language “Haskell”.

Put all the exercise’s into a file called “ps.hs” to run it.

A Makefile is also uploaded, however it is in the form of a “.doc” file, remove it and you should be able to run it.

There is also a Test file uploaded along with it. However to use the Test file you must make it a “.t” file by renaming it and putting it at the end.

#1: Write a function “zeroIsNothing” which

–> converts 0 to Nothing, and any other number to Just that number

–> also write its type signature

zeroIsNothing z

| otherwise = 1

#2: Write a function “nothingIsZero” which

— converts Nothing to 0, and (Just a) to the number a

— also write its type signature

nothingIsZero a = a

#3: Create a typeclass called NumOrString that can contain either an Integer or String object.

— make sure your NumOrString class includes “deriving (Show)” so that

— it may be printed

— write a function makeNum

— which accepts an Integer and produces a NumOrString object that

— encapsulates its value

— also write its type signature

makeNum a = a

#4: Write a function getNum which accepts a NumOrString object

— produces a Maybe object, where

— if the NumOrString object is a number, it should be “Just <that

— number>”

— otherwise, Nothing

— also write its type signature

getNum a = a

#5: Write a function makeString

— which accepts an String and produces a NumOrString object that

— encapsulates its value

— also write its type signature

makeString a = a

#6: Write a function getString which accepts a NumOrString object

— produces a Maybe object, where

— if the NumOrString object is a String, it should be “Just <that

— string>”

— otherwise, Nothing

— also write its type signature

getString a = a

#7: Write a function named “makeNumList” which accepts a numeric argument

— and outputs a list of that many NumOrString objects, counting up

— from 1 to the argument

— e.g. “makeNumList 5” should produce:

— [<NumOrString object with numeric 1>, <NumOrString object with numeric 2>, <NumOrString object with numeric 3>, <NumOrString object with numeric 4>, <NumOrString object with numeric 5>]

— and where

— map getNum <that list> should be [Just 1,Just 2,Just 3,Just 4,Just 5]

— to get the list in the right order, you may need to use Haskell’s append operator, which is ++

— note the type signature of (++) is

— (++) :: [a] -> [a] -> [a]

makeNumList n = [1, 2, 3]

#8: Let’s write bucket in Haskell

— it takes a list of numbers and outputs a list of lists-of-numbers,

— where like numbers are grouped together.

— e.g. bucket [1,1,3,3,3,5,4,4] is
[[1,1],[3,3,3],[5],[4,4]]

— use foldr (fold from the right)

— think about the base case; in this example,

— you’re combining 4 and [] (and you should output [[4]])

— then next you’ll be combining 4 and [[4]]

— and you should output [[4,4]]

— then next you’ll be combining 5 and [[4,4]]

— and you should output [[5],[4,4]]

— define the bucket op fcn first

— name it bucket_op, and write its type signature

bucket_op n l = []

— now write the main bucket (which must use foldr and bucket_op)

bucket l = []

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
error: Content is protected !!