Plutonomicon / plutarch-plutus

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

Update Prefer statically building constants.md #666

Open peter-mlabs opened 5 months ago

SeungheonOh commented 5 months ago

Adding the idea of pre-evaluating terms using evalTerm would be nice

peter-mlabs commented 5 months ago

Can't actually figure out how to do that...

ghci> compile (Config NoTracing) . fromRight' $ evalTerm (Config NoTracing) viacon

<interactive>:23:1: error: [GHC-91028]
    • Couldn't match expected type ‘ClosedTerm a0’
                  with actual type ‘b0’
      Cannot instantiate unification variable ‘b0’
      with a type involving polytypes: ClosedTerm a0
    • In the first argument of ‘(.)’, namely
        ‘compile (Config NoTracing)’
      In the first argument of ‘($)’, namely
        ‘compile (Config NoTracing) . fromRight'’
      In the expression:
        compile (Config NoTracing) . fromRight'
          $ evalTerm (Config NoTracing) viacon

<interactive>:23:43: error: [GHC-91028]
    • Couldn't match type ‘b0’
                     with ‘(Either EvalError (ClosedTerm PScriptPurpose),
                            PlutusCore.Evaluation.Machine.ExBudget.ExBudget, [Text])’
      Expected: Either Text b0
        Actual: Either
                  Text
                  (Either EvalError (ClosedTerm PScriptPurpose),
                   PlutusCore.Evaluation.Machine.ExBudget.ExBudget, [Text])
      Cannot instantiate unification variable ‘b0’
      with a type involving polytypes:
        (Either EvalError (ClosedTerm PScriptPurpose),
         PlutusCore.Evaluation.Machine.ExBudget.ExBudget, [Text])
    • In the second argument of ‘($)’, namely
        ‘evalTerm (Config NoTracing) viacon’
      In the expression:
        compile (Config NoTracing) . fromRight'
          $ evalTerm (Config NoTracing) viacon
      In an equation for ‘it’:
          it
            = compile (Config NoTracing) . fromRight'
                $ evalTerm (Config NoTracing) viacon
SeungheonOh commented 5 months ago

Type is little messy,

unsafeEvalTerm :: Config -> ClosedTerm a -> ClosedTerm a
unsafeEvalTerm c t = go $ evalterm c t
  let 
    go (Right (Right t', _, _)) = t'
    go _ = error "term evaluation failed"
SeungheonOh commented 5 months ago

Any idea why PR's not working..?