Do not hardcode arguments to FunTy
The function type takes 5 arguments (multiplicity, two RuntimeReps, argument, result).
In the compiler, there are many places where we pattern match on lists of length 5, or hardcode particular indices. For example:
decomposeFunCo r co = ASSERT2( all_ok, ppr co )
(mkNthCo Nominal 0 co, mkNthCo r 3 co, mkNthCo r 4 co)
...
go r n co@(FunCo r0 w arg res)
-- See Note [Function coercions]
-- If FunCo _ mult arg_co res_co :: (s1:TYPE sk1 :mult-> s2:TYPE sk2)
-- ~ (t1:TYPE tk1 :mult-> t2:TYPE tk2)
-- Then we want to behave as if co was
-- TyConAppCo mult argk_co resk_co arg_co res_co
-- where
-- argk_co :: sk1 ~ tk1 = mkNthCo 0 (mkKindCo arg_co)
-- resk_co :: sk2 ~ tk2 = mkNthCo 0 (mkKindCo res_co)
-- i.e. mkRuntimeRepCo
= case n of
0 -> ASSERT( r == Nominal ) w
1 -> ASSERT( r == Nominal ) mkRuntimeRepCo arg
2 -> ASSERT( r == Nominal ) mkRuntimeRepCo res
3 -> ASSERT( r == r0 ) arg
4 -> ASSERT( r == r0 ) res
_ -> pprPanic "mkNthCo(FunCo)" (ppr n $$ ppr co)
During development of linear types, we added a new argument and it was hard to find all occurrences.
We should use named constants whenever possible. Instead of lists, we could have pattern synonyms tweag/ghc@0a678646. Last time I've checked though, pattern synonyms caused performance regressions.