I’m writing a simple Abstract Data Type for fractions and
I cant even get the constructor to work, I’m just very lost on SML syntax.
signature fracs = sig
type fraction
exception zero_denominator
(* constructor *)
val // : int * int -> fraction
/*******************************************************************************************************************************************/
that is the .sig file showing the constructor that i am implementing.
Here is what i have so far. the error i recieve is that I’m doing int*int* -> int
when i want int*int-> fraction. I know what its saying and everything, but I just cant make it happen.
structure fracs :> fracs = struct
abstype fraction = frac of int * int
with
exception zero_denominator;
(**********************************)
(*constructor*)
infix 8 //;
fun num // den = if den = 0 then raise zero_denominator
else
num * den;
end;(*end ADT*)
end;(*end struct*)
In function signature,
A * Bmeans a tuple with two elements of typesAandB. However in implementation,A * Bmeans multiplication between two integers.What you want is to make a
fractionvalue from two integers: