I try using foldr to reverse a list like the following
fun rev(l) = foldr (a b => b ++ [a]) [] l;
but I got error : stdIn:4.25 Error: syntax error found at DARROW
Can anyone help to point out the mistake? Is the code correct?
Thank you.
I try using foldr to reverse a list like the following
fun rev(l) = foldr (a b => b ++ [a]) [] l;
but I got error : stdIn:4.25 Error: syntax error found at DARROW
Can anyone help to point out the mistake? Is the code correct?
Thank you.
fn
.fn (a,b)
++
is the concat operator in Haskell. In SML it's @
Which all sum up to:
fun rev(l) = foldr (fn (a,b) => b @ [a]) [] l;
And this indeed reverses a list!