Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In class, we used denotational semantics to evaluate a decimal number using a function Mdec. We could define a similar function to evaluate hexadecimal numbers

In class, we used denotational semantics to evaluate a decimal number using a function Mdec. We could define a similar function to evaluate hexadecimal numbers as follows:

MhexDigit(0) = 0,, MhexDigit(9) = 9,

MhexDigit(A) = MhexDigit(a) = 10,,MhexDigit(B) = MhexDigit(b) = 11,,

MhexDigit(F) = MhexDigit(f) = 15

Mhex(d) = MhexDigit(d) (Base case one-digit string)

Mhex(dndn-1d1d0) = Mhex(dndn-1d1)*16 + MhexDigit(d0)

Note that I am allowing both upper- and lower-case letters for the hexadecimal digits for 10,11,,15. Implement a Haskell function mHexDigit to return the numerical value of a single hexadecimal digit. You will need to use guards and the ord function from the Haskell module Data.Char. The Haskell type should be mHexDigit::Char -> Int Now, implement a Haskell function mHex::String -> Int to evaluate a hexadecimal number given as a string. Finally, since mHexDigit is only used by mHex, implement a Haskell function mHex::String -> Int in which mHexDigit is defined using the where or let contruct.

image text in transcribed

Implement a Haskell function varmap::String -> [(String,Int)] -> Int, based on the denotiationalsemantics function VARMAP, that takes an identifier and a list of identifier-value pairs and returns the value associated with the identifier in the list. To accommodate Haskells static typing, you may assume the values are non-negative integers and use -1 in place of undef. You may also return -1 as an error code if the identifier is not in the list. I am providing some sample runs using the GHCiWin of my implementations of these functions so that you can see how they should work in action (and test your implementation). I am also providing some Haskell functions (together with a sample run) that illustrate the functions ord, chr, fst, and snd that you may find useful.

image text in transcribed

In class, we used denotational semantics to evaluate a decimal number using a function Mdec. We could define a similar function to evaluate hexadecimal numbers as follows: Mhex ("d") Mhexbigit ('d') (Base case one-digit string) - Note that I am allowing both upper- and lower-case letters for the hexadecimal digits for 10,11,. 15. Implement a Haskell function mHexDigit to return the numerical value of a single hexadecimal digit. You will need to use guards and the ord function from the Haskell module Data.Char. The Haskel type should be mHexDigit::Char -> Int a string. Finally, since mHexDigit is only used by mHex, implement a Haskell function mHex':String->Int in which mHexDigit is defined using the where or let contruct. In class, we used denotational semantics to evaluate a decimal number using a function Mdec. We could define a similar function to evaluate hexadecimal numbers as follows: Mhex ("d") Mhexbigit ('d') (Base case one-digit string) - Note that I am allowing both upper- and lower-case letters for the hexadecimal digits for 10,11,. 15. Implement a Haskell function mHexDigit to return the numerical value of a single hexadecimal digit. You will need to use guards and the ord function from the Haskell module Data.Char. The Haskel type should be mHexDigit::Char -> Int a string. Finally, since mHexDigit is only used by mHex, implement a Haskell function mHex':String->Int in which mHexDigit is defined using the where or let contruct

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

Lo6 Identify several management development methods.

Answered: 1 week ago

Question

LO4 List options for development needs analyses.

Answered: 1 week ago