Plutonomicon / plutarch-plutus

Typed eDSL for writing UPLC /ˈpluː.tɑːk/
MIT License
124 stars 64 forks source link

Broken / inconsistent defaulting behaviour with PAsData and record access #570

Open colll78 opened 2 years ago

colll78 commented 2 years ago
listOfIndices <- pletC $ pconstant [1,3,5]
txInputs           <- pletC txInfo.inputs
results <- pletC $ pmap # plam (\i -> pelemAt # i # txInputs) # listOfIndices

Couldn't match type ‘PBuiltinList PTxInInfo’ with ‘PTxInInfo’
        arising from a use of ‘plam’
    • In the second argument of ‘(#)’, namely
        ‘plam (\ i -> pelemAt # i # txInputs)’
      In the first argument of ‘(#)’, namely
        ‘pmap # plam (\ i -> pelemAt # i # txInputs)’
      In the second argument of ‘($)’, namely
        ‘pmap # plam (\ i -> pelemAt # i # txInputs)
           # listOfIndices’

From a user perspective, there are many ways to work around this issue. Namely, by adding a haskell level type annotation to txInputs like so txInputs :: Term s (PBuiltinList PTxInInfo) <- pletC txInfo.inputs

or by explicitly matching against an element of txInputs at the plutarch level type prior to using pmap on txInputs like so, PTxInInfo indexedInput <- pmatchC (pelemAt # someIdx # txInputs)

It can compile with the type annotations / explicit pmatching on an element, but it does not compile without it. Without the type annotations it incorrectly determines that txInput is a single PTxInInfo as opposed to a PBuiltinList with elements of type PTxInInfo.

L-as commented 2 years ago

This is the HasField instance basically breaking Haskell with incoherent instances. We should just remove the incoherent instances, since the behaviour is confusing, and less necessary now after #521