for a homework assignment, a subtask is to make the arithmetic functions (+), (-), (*) and div showable.
We're solved the rest of the assignment, but we're stuck here. Right now we're using the solution to this question here to distinguish between the operations:
showOp op = case op 3 3 of
6 -> "plus"
0 -> "minus"
9 -> "times"
1 -> "divide"
_ -> "undefined"
However, this strikes me as kind of ugly as things like showOp (\a b -> a * 3 - y) yield "plus".
Is there any way to better distinguish between the operators?
We are using winhugs atm with the appropriate switches -98 +o in order to be able to use the needed extensions.
Edit:
As requested, the actual assignment has to do with Arrays (specifically Array Int (Int -> Int -> Int)). It has to do with generating arrays of operators that fulfill certain conditions.
The assignment states:
Make the data type
Array Int (Int->Int-Int)an Instance ofShow. The arithmetic operations from the previous exercises should be represented as "plus", "minus", "times" and "div".
thx for any help in advance
Int->Int->Int, there is little better you can do than such a heuristic unsafe case table. (It would be possible to make it much nicer if general(Num a) => a->a->awas allowed...)Int -> Int -> Intfor extensional equality easily enough. You just need to apply both functions to all possible arguments and check that they produce the same result! It might take a while, though.Intis bounded. But I do get somewhat impatient...