Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active June 15, 2017 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/84380918206dc37994696e71b8534cd3 to your computer and use it in GitHub Desktop.
Save deque-blog/84380918206dc37994696e71b8534cd3 to your computer and use it in GitHub Desktop.
score' : Nat -> Vect n Frame -> List Nat -> Nat
score' current [] _ = current
score' current (f :: fs) rolls =
let frameRollNb = length (knockedPins f) -- Nb of rolls in the frame
scoreRollNb = frameRollNb + bonusRolls f -- Nb of rolls to sum
frameScore = sum (take scoreRollNb rolls) -- Sum of the rolls to sum
in score' -- Recur:
(current + frameScore) -- Add the frame score to the current score
fs -- Advance the the next frame
(drop frameRollNb rolls) -- Advance to the next rolls
score : BowlingGame -> Nat
score game@(MkBowlingGame frames bonus) = score' 0 frames (gameRolls game)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment