On Wed, 2006-10-04 at 20:41 -0700, Erick Tryzelaar wrote:
> A minor problem I ran into while playing around with the testing of the 
> stdlib. I'd like to be able to insert debugging code into a pattern 
> match, but in order to do that, I have to make everything into an 
> anonymous function. I wish I could do something like this:
> 
> fun map[T,U] (f:T->U) (x:list[T]) =>
>   match x with
>   | Empty[T] => Empty[U]
>   | Cons(?h, ?t) =>
>       print "hello"; endl;
>       Cons(_f h, map f x)
>   endmatch
> ;

The problem is the RHS of => must be an expression. So what you
want in the first instance is a function like:

        fun second[t] (a:unit,b:t):t => b

which ignores the first argument and returns the second one.
Then you could write

        second$ { print "Debug"; return (); } (), b

Of course, there's a risk Felix will elide the call to
the useless first argument, but that's easy to fix 
with a C hack:

        fun second[t]: (1->0) * t ->t = "run ($1),$2";

where somehow 'run $1' runs a procedure closure.
(there's a Felix function to do that in the library
but no C function .. I need to fix that).



-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to