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

Have when work also not within always #11

Open
gameboo opened this issue Feb 17, 2019 · 2 comments
Open

Have when work also not within always #11

gameboo opened this issue Feb 17, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@gameboo
Copy link
Collaborator

gameboo commented Feb 17, 2019

I think it would be nice to have when work as a when :: Bit 1 -> Action () -> Module () on top of just when :: Bit 1 -> Action () -> Action (). I'd like to write something like

top = do
  cycleCount :: Reg (Bit 8) <- makeReg 0
  -- Increment cycleCount on every cycle
  always do
    cycleCount <== cycleCount.val + 1
  -- Terminate simulation when count reaches 20
  when (cycleCount.val .==. 20) do
    display "Finished"
    finish

instead of

top = do
  cycleCount :: Reg (Bit 8) <- makeReg 0
  always do
    -- Increment cycleCount on every cycle
    cycleCount <== cycleCount.val + 1
    -- Terminate simulation when count reaches 20
    when (cycleCount.val .==. 20) do
      display "Finished"
      finish

or

top = do
  cycleCount :: Reg (Bit 8) <- makeReg 0
  -- Increment cycleCount on every cycle
  always do
    cycleCount <== cycleCount.val + 1
  -- Terminate simulation when count reaches 20
  always do
    when (cycleCount.val .==. 20) do
      display "Finished"
      finish
@mn416
Copy link
Collaborator

mn416 commented Feb 17, 2019

Yeah, library seems happy if we introduce

class When m where
  when :: Bit 1 -> Action () -> m ()

with instances for Module and Action.

Just wondering if there are any annoying cases when the type is no longer inferred. The other option is to have a new function, e.g. on, or whenever.

@gameboo
Copy link
Collaborator Author

gameboo commented Feb 17, 2019

I think I prefer the same name but I don't know how likely it would be for the type not to be inferred correctly...
<troll>if only Action and Module where the same</troll>

@gameboo gameboo added the enhancement New feature or request label Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants