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

Use Haskell for the above problems. Unless stated otherwise do not use library f

ID: 3839230 • Letter: U

Question

Use Haskell for the above problems. Unless stated otherwise do not use library functions that are not in the Haskell standard prelude.

6. 12 marks Write a function isNumber String Bool that tests if a string contains a valid number. A valid number is defined in EBNF as: number .digit I digit+ (.digit For example .5, 1.5 1, 1. are all valid numbers. As usual, signifies one or more occurrences, and denotes zero or more You may use the isDigit function from the Data Char module Hint: you may wish to write functions gits, many Digits String Bool to test for digit+ and digit

Explanation / Answer

Analyzing your problem statement what I fond is that we can solve the question in two ways

Please find the below explanation and necessary code for the same

Way no 01

********************************

Haskell:

This function is not particularly useful in a statically typed language. Instead, one would just attempt to convert the string to the desired type with read or reads, and handle parsing failure appropriately.

The task doesn't define which strings are considered "numeric", so we do Integers and Doubles, which should catch the most common cases (including hexadecimal 0x notation):

*******************************

Way 02

use the Data.Char module, allowing code such as:

so read s::Int (for instance) could be reliably used if string s passed these tests.

*********************

P.S KINDLY NOTE THAT 2ND WAY IS THE EXACT SOLUTION FOR YOUR PROBLEM STATEMENT AND YOU CAN REFER WAY NO 01 AS ITS ALSO PART OF HASKELL MODULE

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