kvajnto
04-06-2004, 11:31 AM
'm just beginning to learn SML (been learning from a book for like a week or so now). I don't have anyone to ask questions, so hopefully someone could help me here.
I'm having a hard time understanding this function found in the book I'm using. I don't really understand it fully.
fun countLEG [] = (0,0,0)
| countLEG(x::rest) =
let val (y1,y2,y3) = countLEG rest in
case Int.compare(x,0) of
LESS => (y1+1,y2 ,y3 )
| EQUAL => (y1 ,y2+1,y3 )
| GREATER => (y1 ,y2 ,y3+1)
end;
Can you use a value such as a tupel as an identifier for an expression (countLEG rest)? Also, let's say the first value in the list is less than 0, then you add 1 to y1. Will this not change the way that countLEG rest is calculated? Why not? if you have something like
a = b * c + d
and then add 1 to a, the right hand side will change as well. I do understand that I'm thinking wrong, I'm not trying to convince anyone that something is wrong with SML =)
I understand what the function does (presents a three tupel that represent how many values in a list are less, equal or greater than 0), but not how it does it.
If anyone could explain it to me I would be REALLY greatfull.
Thanks in advance and sorry for my bad english.
I'm having a hard time understanding this function found in the book I'm using. I don't really understand it fully.
fun countLEG [] = (0,0,0)
| countLEG(x::rest) =
let val (y1,y2,y3) = countLEG rest in
case Int.compare(x,0) of
LESS => (y1+1,y2 ,y3 )
| EQUAL => (y1 ,y2+1,y3 )
| GREATER => (y1 ,y2 ,y3+1)
end;
Can you use a value such as a tupel as an identifier for an expression (countLEG rest)? Also, let's say the first value in the list is less than 0, then you add 1 to y1. Will this not change the way that countLEG rest is calculated? Why not? if you have something like
a = b * c + d
and then add 1 to a, the right hand side will change as well. I do understand that I'm thinking wrong, I'm not trying to convince anyone that something is wrong with SML =)
I understand what the function does (presents a three tupel that represent how many values in a list are less, equal or greater than 0), but not how it does it.
If anyone could explain it to me I would be REALLY greatfull.
Thanks in advance and sorry for my bad english.