Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Haskell language Part 2 Type System Total: 35 Points Problem 3 [35 Points]. Declare a data type MyFraction for handling fractions -- where each

"In Haskell language"

Part 2 Type System

Total: 35 Points

Problem 3 [35 Points]. Declare a data type MyFraction for handling fractions -- where each number is a (numerator, denominator) pair of integers representing the numerator and the denominator of the fraction. For example, (22, 23) would represent 22 / 23. The numerator can be positive or negative, and the denominator must always be positive.

Carefully pick Haskell's built-in type classes which this type should be an instance of. You should define and when meaningful overload simple arithmetic and comparison operations on these fractions (at least: *, /, +, -, neg (negation), <=, >=, <, >, ==). Also define functions numerator and denominator to return the numerator and denominator, and functions whole and fractional to extract the whole and the fractional part of the fraction. For example, for (23, 22), whole should return 1, and fraction should return 1 / 22. Function fractional should return a MyFraction data type.

"In Haskell language"

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_2

Step: 3

blur-text-image_3

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

What is Larmors formula? Explain with a suitable example.

Answered: 1 week ago