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

StaticEither accessors #4263

Merged
merged 2 commits into from
Jan 10, 2023
Merged

Conversation

jorisdral
Copy link
Contributor

@jorisdral jorisdral commented Jan 10, 2023

Description

Closes #4232.

The StaticEither datatype encodes its "left-ness" or "right-ness" in a type-level Bool.

data StaticEither :: Bool -> Type -> Type -> Type where
  StaticLeft  :: l -> StaticEither False l r
  StaticRight :: r -> StaticEither True  l r

As a consequence, when the type-level Bool becomes concrete (i.e., 'True or 'False'), we can only match on one of the constructors.

case sl of StaticLeft x -> x
let StaticLeft x = sl
case sr of StaticRight x -> x
let StaticRight x = sr 

We add two helper functions, that are analogous to fromLeft and fromRight, but without the default value that fromLeft and fromRight require to be total functions.

fromStaticLeft :: StaticEither 'False l r -> l
fromStaticLeft = \case (StaticLeft x) -> x

fromStaticRight :: StaticEither 'True l r -> r
fromStaticRight = \case (StaticRight x) -> x

Checklist

  • Branch
    • Commit sequence broadly makes sense
    • Commits have useful messages
    • New tests are added if needed and existing tests are updated
    • If this branch changes Consensus and has any consequences for downstream repositories or end users, said changes must be documented in interface-CHANGELOG.md
    • If this branch changes Network and has any consequences for downstream repositories or end users, said changes must be documented in interface-CHANGELOG.md
    • If serialization changes, user-facing consequences (e.g. replay from genesis) are confirmed to be intentional.
  • Pull Request
    • Self-reviewed the diff
    • Useful pull request description at least containing the following information:
      • What does this PR change?
      • Why these changes were needed?
      • How does this affect downstream repositories and/or end-users?
      • Which ticket does this PR close (if any)? If it does, is it linked?
    • Reviewer requested

@jorisdral jorisdral added consensus issues related to ouroboros-consensus technical debt UTxO-HD 📒💽 labels Jan 10, 2023
@jorisdral jorisdral requested a review from nfrisby as a code owner January 10, 2023 10:20
@jorisdral jorisdral self-assigned this Jan 10, 2023
@jorisdral jorisdral removed the request for review from nfrisby January 10, 2023 10:20
@jorisdral jorisdral linked an issue Jan 10, 2023 that may be closed by this pull request
Remove `LambdaCase`

Co-authored-by: amesgen <alexander.esgen@iohk.io>
Copy link
Contributor

@jasagredo jasagredo 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

@jorisdral jorisdral merged commit bcb4c81 into feature/utxo-hd Jan 10, 2023
@jorisdral jorisdral deleted the jdral/4232-static-either-accessors branch January 10, 2023 13:52
jasagredo pushed a commit that referenced this pull request Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus issues related to ouroboros-consensus technical debt UTxO-HD 📒💽
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tech debt: StaticEither accessors for more easy manipulation
3 participants