[Haskell-cafe] Java or C to Haskell

Carajillu crespi.albert at gmail.com
Wed Sep 20 04:31:22 EDT 2006


I'm trying to write in Haskell a function that in Java would be something
like this:

char find_match (char[] l1, char[] l2, char e){
	//l1 and l2 are not empty
	int i = 0;
	while (l2){
		char aux = l2[i];
		char[n] laux = l2;
		while(laux){
			int j = 0;
			if(laux[j] = aux) laux[j] = e;
				j++;
		}
		if compare (l1, laux) return aux;
		else i++;
	}
return '';
}

compare function just compares the two lists and return true if they are
equal, or false if they are not.
it is really a simple function, but I've been thinking about it a lot of
time and I can't get the goal. It works like this:

find_match "4*h&a" "4*5&a" 'h' ----> returns '5' (5 matches with the h)
find_match "4*n&s" "4dhnn" "k" ----> returns ''  (no match at all - lists
are different anyway)

I'm trying to use map for scanning the list l2, then using some function for
substitute the char, and finally something like zipWith x == y laux l1 for
comparing the lists, but I can't find a way for putting all this together!!
-- 
View this message in context: http://www.nabble.com/Java-or-C-to-Haskell-tf2303820.html#a6403589
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list