I'm practicing with sml and I'm doing a small assignment where we have to implement church numerals defined as:
datatype 'a church = C of ('a -> 'a) * 'a -> 'a
example val
ZERO = C(fn (f,x) => x)
I have already implemented the functions:
create: int -> 'a church
churchToInt: 'a church -> int
and SUC which returns the successor of a church numeral.
Now I have to implement the function
PRED: 'a church -> 'a church * 'a church
which returns the tuple of (predecessor, current numeral). I am not allowed to use churchToInt, I should directly work with church numerals. Apparently this is solvable in one line by passing a specific argument.
I was thinking of just using SUC over and over until we hit the right number but there is no way for me to compare the 2 church numerals. I am completely stuck on this.
Any help is appreciated, Thanks