0

I have the following function:

getcountof(x,l::ls) = 
if x=l then  (1 + getcountof(x,ls))
else getcountof(x,ls)
|getcountof(x,[]) = 0;

Can someone tell me whats wrong in it? I get the error:

stdIn:1.2-1.17 Error: syntax error: deleting  ELSE ID
stdIn:1.22-20.12 Error: syntax error: deleting  RPAREN BAR ID
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Rpant
  • 974
  • 2
  • 14
  • 37

1 Answers1

1

You've missed the fun keyword from the start of your definition!

Try this instead:

fun getcountof(x,l::ls) = 
     if x=l then  (1 + getcountof(x,ls))
     else getcountof(x,ls)
  | getcountof(x,[]) = 0;

This is a trap for people familiar with Haskell.

Gian
  • 13,735
  • 44
  • 51