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

parameterized patterns #283

Open
lutzhamel opened this issue Jun 14, 2023 · 1 comment
Open

parameterized patterns #283

lutzhamel opened this issue Jun 14, 2023 · 1 comment
Assignees
Labels
enhancement Features that are directly related to the core tenet of Asteroid

Comments

@lutzhamel
Copy link
Collaborator

An idea on how to look at parameterized patterns. Currently Asteroid supports parameterized patterns via variables read from the environment,

Asteroid Version 2.0.1alpha
(c) University of Rhode Island
Type "asteroid -h" for help
Press CTRL-D to exit
ast> let p = pattern %integer.
ast> let pair = pattern (x:*p,y:*p).
ast> let q:*pair = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)
ast> let p = pattern %real. -- now pair is a pair of real values
ast> let q:*pair = (1,2).
error: pattern match failed: conditional pattern match failed
ast> let q:*pair = (1.1,2.2).
ast> 

This is very clumsy and prone to programming errors...think dynamically scoped functions. A nice way would be to actually have have parameters on the pattern. Something like this perhaps,

ast> let p = pattern %integer.
ast> let pair = pattern with a match (x:*a,y:*a).
ast> let q:*pair(p) = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)

or in more concise form,

ast> let pair = pattern with a match (x:*a,y:*a).
ast> let q:*pair(pattern %integer) = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)
ast> let q:*pair(pattern %real) = (1.1,2.2). -- here pair is a pair of real values
ast> q
(1.1,2.2)
@lutzhamel lutzhamel self-assigned this Jun 14, 2023
@lutzhamel lutzhamel added the enhancement Features that are directly related to the core tenet of Asteroid label Jun 14, 2023
@lutzhamel lutzhamel added this to the Release 2.0.1 milestone Jun 14, 2023
@lutzhamel
Copy link
Collaborator Author

We cannot use juxtaposition as a way to parameterize patterns, it makes the language too ambiguous due to the confusion with function application. We can adopt the generics notation here,

ast> let pair = pattern<a> (x:*a,y:*a).
ast> let q:*pair<pattern %integer> = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)
ast> let q:*pair<pattern %real> = (1.1,2.2). -- here pair is a pair of real values
ast> q
(1.1,2.2)

@lutzhamel lutzhamel removed this from the Release 2.0.1 milestone Jun 23, 2023
lutzhamel pushed a commit that referenced this issue Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Features that are directly related to the core tenet of Asteroid
Projects
None yet
Development

No branches or pull requests

1 participant