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

Allow irrefutable patterns as function parameters #94

Merged
merged 7 commits into from
Nov 1, 2022

Conversation

jmackie
Copy link
Member

@jmackie jmackie commented Oct 31, 2022

This makes working with type "wrappers" (a.k.a newtype*) much more ergonomic by removing the need for single arm match expressions.

Before:

module Wrapper exports (Wrapper, unwrap);

type Wrapper(a) = Wrapper(a);

unwrap = fn (wrapper) -> 
    match wrapper with
    | Wrapper(a) -> a
    end;

After:

module Wrapper exports (Wrapper, unwrap);

type Wrapper(a) = Wrapper(a);

unwrap = fn (Wrapper(a)) -> a;

This becomes especially powerful once we support a richer pattern syntax 👌.

*I know "wrappers" like this aren't really newtypes as they have a runtime cost...

@jmackie jmackie linked an issue Oct 31, 2022 that may be closed by this pull request
2 tasks
@jmackie jmackie added this to the 0.0.2 milestone Oct 31, 2022
@jmackie jmackie mentioned this pull request Oct 31, 2022
2 tasks
@codecov
Copy link

codecov bot commented Oct 31, 2022

Codecov Report

Merging #94 (847691e) into main (ee473a5) will increase coverage by 0.00%.
The diff coverage is 84.61%.

@@           Coverage Diff           @@
##             main      #94   +/-   ##
=======================================
  Coverage   73.89%   73.90%           
=======================================
  Files         111      111           
  Lines        8314     8319    +5     
=======================================
+ Hits         6144     6148    +4     
- Misses       2170     2171    +1     
Impacted Files Coverage Δ
crates/ditto-checker/src/result/type_error.rs 95.83% <0.00%> (-3.10%) ⬇️
...ates/ditto-checker/src/typechecker/substitution.rs 77.47% <ø> (ø)
crates/ditto-cst/src/get_span.rs 91.02% <ø> (-0.44%) ⬇️
crates/ditto-fmt/src/has_comments.rs 46.37% <ø> (+0.27%) ⬆️
crates/ditto-checker/src/typechecker/mod.rs 82.07% <65.21%> (-1.31%) ⬇️
crates/ditto-codegen-js/src/convert.rs 96.44% <96.42%> (-0.03%) ⬇️
crates/ditto-ast/src/expression.rs 81.63% <100.00%> (+4.43%) ⬆️
...ditto-checker/src/module/value_declarations/mod.rs 91.25% <100.00%> (+0.16%) ⬆️
crates/ditto-checker/src/typechecker/pre_ast.rs 100.00% <100.00%> (ø)
crates/ditto-fmt/src/expression.rs 100.00% <100.00%> (+0.67%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jmackie jmackie merged commit edc8829 into main Nov 1, 2022
@jmackie jmackie deleted the pattern-function-binders branch November 1, 2022 11:07
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.

Use patterns for binders
1 participant