Closed jespercockx closed 4 months ago
At the moment, tuple projections are not yet supported, and I'm not sure what's the best way to handle them. Here are two options:
fst
and snd
(but what to do about tuples with more than 2 components?)A hybrid (2 for binary tuples, 1 for everything else) is also possible in theory.
One more option I just thought of: take option 1 except that for binary tuple types, we check that the projections are called fst
and snd
, and we don't generate any code in that case.
EDIT: actually, record projections are not compiled unless they have their own COMPILE
pragma, so perhaps there is nothing that really needs to be changed. If users want to define their own record types that use Haskell's built-in fst
and snd
projections, they can do so by declaring rewrite rules for the projections.
This PR addresses the first point in #105 by adding support for compiling an Agda record type to a Haskell tuple. The feature is designed to be pretty flexible, so you can compile any record type and
agda2hs
will just take the (compiled) field types as the tuple components. It also allows defining unboxed tuples, which was previously not supported byagda2hs
. However, there are no checks in place that the rules for unboxed tuples are followed, so it might generate invalid Haskell code if used improperly.