| Author |
what is wrong w\this
|
|
|
| Hi
I am new to ml. i am trying to write a function which returns true if
2 of the elem which are next to each other in a given list are the
same and false if not. this is what i came up with, not working! any
help
thx
fun check (x,nil) = false
| check (x, (y :: ys)) = (
if (x = y) then true
else false;
fun fid nil = false
| fid (y :: ys) = ( check (y, (fid ys)) );
| |
|
| & is there an easier way where i can do this using only one function ?
| |
|
| JS_Y wrote:
> & is there an easier way where i can do this using only one function ?
Maybe something like this:
fun fid [] = false
| fid [x] = false
| fid (x::y::ys) = if (x=y) then true else fid (y::ys);
| |
| Ivan Jager 2007-05-30, 10:06 pm |
| On 2007-05-29, cane <xxx@xxx.com> wrote:
> JS_Y wrote:
>
> Maybe something like this:
>
> fun fid [] = false
>| fid [x] = false
>| fid (x::y::ys) = if (x=y) then true else fid (y::ys);
Or if you want something shorter:
fun fid (x::y::ys) = x=y orelse fid (y::ys)
| fid _ = false
Ivan :)
|
|
|
|