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

fix(stdlib): Allow destructuring of TypedPath tuple #1604

Closed
wants to merge 1 commit into from

Conversation

av8ta
Copy link
Contributor

@av8ta av8ta commented Jan 16, 2023

@alex-snezhko I was having some trouble destructuring TypedPath tuples due to type errors.

I found by exporting: export type TypedPath<a, b> = (TBase<a>, TFileType<b>, List<String>), I'm able to destructure it fine now. Is it okay to expose this? Or were you wanting consumers to always interact with Path using provided functions?

match (Path.fromString("./dir1/dir2/dir3")) {
  Path.RelativeFile(x) => {
    let (base, fileType, pathArray) = x           // type error here
    assert pathArray == ["dir3", "dir2", "dir1"]
  },
  _ => fail "not a relative file",
}
This expression has type Path.TypedPath<Path.Relative, Path.File>
but an expression was expected of type (a, b, c)

@phated
Copy link
Member

phated commented Jan 16, 2023

This is not supposed to be exported.

@alex-snezhko
Copy link
Member

I was originally going to leave this hidden but I believe we arrived at exposing it as per this discussion

@phated
Copy link
Member

phated commented Jan 16, 2023

The internal representation of the TypedPath should never be exposed. You can still pattern match on the Path type and alias the value to use with other functions in Path (for specialized behavior, etc).

This will be expanded once we have in-file modules so you can use specific APIs for specific types of paths.

@phated phated closed this Jan 16, 2023
@av8ta
Copy link
Contributor Author

av8ta commented Jan 16, 2023

That makes sense.

You can still pattern match on the Path type and alias the value to use

Thanks! That was the clue I needed :)

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.

3 participants