I have an assignment where I have to implement church numerals in sml using the datatype: datatype 'a church = C of ('a -'a) * 'a -> 'a I have to write the function create :int -> 'a church and a function churchToint so far I have the following code:
datatype 'a church = C of ('a -> 'a) * 'a -> 'a
val ZERO = C(fn (f,x) => x)
fun subCreate 0 (f,x) = x
| subCreate n (f,x) = f (subCreate (n-1) (f,x))
fun create n = C(fn (f,x) => subCreate n (f,x));
fun churchToInt cn = cn (fn x => x + 1) 0;
I know i am pretty close but not quite. Can you please tell me where I am going wrong? Thanks