Skip to content

Instantly share code, notes, and snippets.

@simonmichael
Last active March 1, 2019 22:51
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 simonmichael/5ed0ad2c76b2f3452d0c260343d0a542 to your computer and use it in GitHub Desktop.
Save simonmichael/5ed0ad2c76b2f3452d0c260343d0a542 to your computer and use it in GitHub Desktop.
strange non-exhaustive error with GHC 7
addOrAssignAmountAndCheckAssertionB :: Posting -> Balancing s Posting
addOrAssignAmountAndCheckAssertionB p@Posting{paccount=acc, pamount=amt, pbalanceassertion=mba} -- line 730
| hasAmount p = do
newbal <- addAmountB acc amt
whenM (R.reader bsAssrt) $ checkBalanceAssertionB p newbal
return p
| Nothing <- mba = return p
| Just BalanceAssertion{baamount,batotal} <- mba = do
(diff,newbal) <- case batotal of
True -> do
-- a total balance assignment
let newbal = Mixed [baamount]
diff <- setAmountB acc newbal
return (diff,newbal)
False -> do
-- a partial balance assignment
oldbalothercommodities <- filterMixedAmount ((acommodity baamount /=) . acommodity) <$> getAmountB acc
let assignedbalthiscommodity = Mixed [baamount]
newbal = oldbalothercommodities + assignedbalthiscommodity
diff <- setAmountB acc newbal
return (diff,newbal)
let p' = p{pamount=diff, poriginal=Just $ originalPosting p}
whenM (R.reader bsAssrt) $ checkBalanceAssertionB p' newbal
return p'
{-
GHC 7.10.3:
/home/simon/src/hledger/hledger-lib/Hledger/Data/Journal.hs:730:1: Warning:
Pattern match(es) are non-exhaustive
In an equation for ‘addOrAssignAmountAndCheckAssertionB’:
Patterns not matched: Posting _ _ _ _ _ _ _ _ _ _ _
GHC 8+: ok
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment