tags:

views:

217

answers:

2

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

A: 

This is word for word copied from an assignment for a computer science course at a large Canadian University.

Justice
Word for word, really? It seems rather weird for a university to phrase its assignments in first person ("*I* have to implement the function...").
sepp2k
A: 

You must have forced it to by an int in your subPred.

John Doe