Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started