tuple component functions
Nils Decker
ndecker@gmx.de
Fri, 3 Jan 2003 15:33:47 +0100
ketil@ii.uib.no (Ketil Z. Malde) wrote:
> I'd like a general 'nth', but of course that would restrict us to
> monotyped tuples (e.g.,
>
> nth :: Int -> (a,a,...,a,a) -> a
> )
Under [1] you find an interesting proposal for Template Haskell.
I don't know, how far it is from beiing implemented, but it would
allow
$(sel 1 3) x
to be replaced by
(\x -> case x of (a, b, c) -> a) x
at compile time. (example from the paper)
Using "program reflection" it should even be possible to detect the size
of the tuple at compile time, giving your nth function with a slightly
different syntax.
Regards
Nils Decker
[1] http://research.microsoft.com/Users/simonpj/papers/meta-haskell/
--
Nils Decker <ndecker@gmx.de>