Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for true higher-order builtins #6563

Open
effectfully opened this issue Oct 12, 2024 · 0 comments
Open

Add support for true higher-order builtins #6563

effectfully opened this issue Oct 12, 2024 · 0 comments
Labels

Comments

@effectfully
Copy link
Contributor

effectfully commented Oct 12, 2024

Once pattern matching builtins land (see this for a detailed description) we'll be able to return an iterated application from a builtin. Unfortunately, that still doesn't enable us to have higher-order builtins that compute functions supplied as arguments. A prime example of such a builtin is unionWithBSMap, a Plutus version of
Screenshot from 2024-10-12 08-00-34

The usefulness of such a builtin was discussed here.

So let's say we had the following built-in type:

data T a = B a | L

how would we implement zipWithT such that

zipWithT addInteger (B 1 (B 2 L L) L) (B 3 (B 4 L L) L)

computes to B 4 (B 6 L L) L?

One thing we could try is to do a similar thing to pattern matching builtins and return an iterated application where

(1) the spine is the parts that need to be computed on the Plutus side
(2) the head is a BuiltinRuntime constructed on the fly that expects computed terms from (1) to get fed back into the builtin

Denoting (2) in braces, we get something like this:

headSpine {\x y -> B x (B y) L L} [headSpine addInteger [1, 3], headSpine addInteger [2, 4]]

Here the spine is

[headSpine addInteger [1, 3], headSpine addInteger [2, 4]]

which computes to [4, 6]. And the head is

{\x y -> B x (B y) L L}

which is pseudocode for a BuiltinRuntime expecting two arguments and producing the final result.

You can think of this as adding support for built-in functions that return other built-in functions with some computations being cached inside.

To be continued.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant