1

I have to create a function about peano numbers defined as the following datatype:

datatype 'a peano = P of ('a -> 'a) * 'a -> 'a
val zero = P(fn (f, x) => x)

The function that I have to implement finds the succesive peano number of the peano parameter P(p). This is what I have written:

fun suc (P(p)) = case P(p) of P(fn(f,x)=>x) => P(fn(f,x)=>f(x));

The problem is that i get these errors:

stdIn:4.33-4.36 Error: syntax error: deleting FN LPAREN
stdIn:4.43 Error: syntax error found at RPAREN

I don't know what Im doing wrong. Please help!

1 Answer 1

1

There are a number of problems in this code. The one the compiler is whining about is that you have a function definition

fn (f,x) => x

on the left-hand side of a case arm, where only patterns are permitted.

Some other problems:

  1. Redundant parentheses make the code hard to read (advice is available on removing them).
  2. Your case expression is redundant; in the function definition

     fun suc (P p) = ...
    

    it should be possible just to compute with p without any more case analysis.

  3. Since P carries a function, you will probably have an easier time if you write

     fun suc (P f) = ...
    

    and make sure that in the result, f is applied to a pair (as required by the datatype declarations).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.