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

Educational: built-in map primitive #1093

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

normanrink
Copy link
Contributor

@normanrink normanrink commented Sep 27, 2022

This is educational work.
DO NOT MERGE.

Implement a built-in map primitive for mapping a function over an array.

The concrete syntax for the implemented map primitive is map_ <function> over_ <array>. Example: map_ (\x. 2 * x) over_ [0, 1, 2, 3] will evaluate to [0, 2, 4, 6].

@normanrink normanrink marked this pull request as ready for review September 27, 2022 14:53
@normanrink normanrink marked this pull request as draft September 27, 2022 15:03
@normanrink normanrink marked this pull request as ready for review September 27, 2022 15:05
This leads to simplification in type inference since the construction of a `TabLam` (that was previously the single argument of `Map`) is no longer required there.
Copy link
Collaborator

@apaszke apaszke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

TabPi (TabPiType (_:>ixTy) _) <- getType array'
buildTabLam noHint ixTy \i -> do
locals <- tabApp (sink ans) $ Var i
ithArg <- emitAtomToName =<< (tabApp (sink array') $ Var i)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of emitting to name, you could b @> SubstVal ithArg below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

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

Successfully merging this pull request may close these issues.

2 participants