Page 35, sList :: SList xss is probably relevant, but ... going with the MkSum to begin with, and to get it all to compile. The above code is also buggy, so I had to manually derive instances for now,
-- | TODO: Use the injections from `generics-sop`.classMkSum(before::[[Type]])(x::[Type])(xs::[[Type]])wheremkSum'::NPIx->NS(NPI)(Append(Reversebefore)(x':xs))instanceMkSum'[]xxswheremkSum'=ZinstanceMkSum'[p1]xxswheremkSum'=S.ZinstanceMkSum'[p1, p2]xxswheremkSum'=S.S.ZinstanceMkSum'[p1, p2, p3]xxswheremkSum'=S.S.S.ZinstanceMkSum'[p1, p2, p3, p4]xxswheremkSum'=S.S.S.S.ZinstanceMkSum'[p1, p2, p3, p4, p5]xxswheremkSum'=S.S.S.S.S.ZinstanceMkSum'[p1, p2, p3, p4, p5, p7]xxswheremkSum'=S.S.S.S.S.S.Z
This makes MkSum generic, but I'm still not happy. Looks too complex,
classMkSumidxxsswheremkSum::NPI(TypeAtidxxss)->NS(NPI)xssinstanceMkSum'FZ(xs':xss)wheremkSum=ZinstanceMkSumidxxss=>MkSum('FSidx)(xs':xss)wheremkSumv=S$mkSum@idx@xssvtypefamilyLengthxss::N.NatwhereLength'[]='N.ZLength(x':xs)='N.S(Lengthxs)classTail'(idx::Finn)(xss::[[k]])wheretypeTailidxxss::[[k]]instanceTail''FZxsswheretypeTail'FZxss=xssinstanceTail'idxxs=>Tail'('FSidx)(x':xs)wheretypeTail('FSidx)(x':xs)=TailidxxsinstanceTail'idxxs=>Tail'('FSidx)'[]wheretypeTail('FSidx)'[]=TypeError('Text"Tail: index out of bounds")classTypeAt'(idx::Finn)(xs::[[k]])wheretypeTypeAtidxxs::[k]instanceTypeAt''FZ(x':xs)wheretypeTypeAt'FZ(x':xs)=xinstanceTypeAt'('FSidx)(x':xs)wheretypeTypeAt('FSidx)(x':xs)=TypeAtidxxs
Hackage: https://hackage.haskell.org/package/generics-sop-0.5.1.2/docs/Generics-SOP.html#g:9
I don't really understand the
Injection
type, but I should.I was constructing sums by doing manual plumbing, which I suspect is the result of not understanding the above,
I'm loving https://github.com/kosmikus/SSGEP/blob/master/LectureNotes.pdf so far, because there is a natural progression to understanding the seemingly gnarly things in generics-sop Hackage.
Page 35,
sList :: SList xss
is probably relevant, but ... going with theMkSum
to begin with, and to get it all to compile. The above code is also buggy, so I had to manually derive instances for now,https://github.com/Plutonomicon/plutarch/commit/a6343c99ba11390cc9dfa9c73c600a9d04cdf08c
will aggregate these eventually to https://ladder.haskell.page/5/Generic
https://stackoverflow.com/questions/70824108/creating-a-sum-type-using-generics-sop
This makes
MkSum
generic, but I'm still not happy. Looks too complex,Looks like this is not possible, but hey - that StackOverflow answer (which looks to be wrong) had me use Nat from base:
This code is used here: https://twitter.com/sridca/status/1485656368635912198
Niiiice https://twitter.com/sridca/status/1485656368635912198/photo/1
- slow (@sridca)