<commit_before>{-# LANGUAGE GADTs, RecordWildCards, ScopedTypeVariables, FlexibleContexts, FlexibleInstances #-}
{-# OPTIONS_GHC -F -pgmF MonadLoc #-}

module YaLedger.Kernel where

import Control.Applicative ((<$>))
import Control.Monad
import Control.Monad.State
import Control.Monad.Exception
import Control.Monad.Exception.Base
import Control.Monad.Loc
import Control.Monad.Trans
import Data.List
import Data.Dates
import Data.Decimal
import qualified Data.Map as M
import Text.Regex.PCRE
import Text.Printf

import YaLedger.Types
import YaLedger.Tree
import YaLedger.Monad
import YaLedger.Exceptions
import YaLedger.Correspondence

class CanCredit a where
  credit :: (Throws InternalError l,
             Throws NoSuchRate l)
         => a
         -> Ext (Posting Decimal Credit)
         -> Ledger l ()

class CanDebit a where
  debit :: (Throws InternalError l,
            Throws NoSuchRate l)
        => a
        -> Ext (Posting Decimal Debit)
        -> Ledger l ()

instance CanDebit (Account Debit) where
  debit (DAccount {..}) p = do
      appendIOList debitAccountPostings p

instance CanDebit (Account Free) where
  debit (FAccount {..}) p = do
      appendIOList freeAccountDebitPostings p

instance CanCredit (Account Credit) where
  credit (CAccount {..}) p = do
      appendIOList creditAccountPostings p

instance CanCredit (Account Free) where
  credit (FAccount {..}) p = do
      appendIOList freeAccountCreditPostings p

instance CanCredit (FreeOr Credit Account) where<commit_msg>credit / debit do not throw NoSuchRate.<commit_after>{-# LANGUAGE GADTs, RecordWildCards, ScopedTypeVariables, FlexibleContexts, FlexibleInstances #-}
{-# OPTIONS_GHC -F -pgmF MonadLoc #-}

module YaLedger.Kernel where

import Control.Applicative ((<$>))
import Control.Monad
import Control.Monad.State
import Control.Monad.Exception
import Control.Monad.Exception.Base
import Control.Monad.Loc
import Control.Monad.Trans
import Data.List
import Data.Dates
import Data.Decimal
import qualified Data.Map as M
import Text.Regex.PCRE
import Text.Printf

import YaLedger.Types
import YaLedger.Tree
import YaLedger.Monad
import YaLedger.Exceptions
import YaLedger.Correspondence

class CanCredit a where
  credit :: (Throws InternalError l)
         => a
         -> Ext (Posting Decimal Credit)
         -> Ledger l ()

class CanDebit a where
  debit :: (Throws InternalError l)
        => a
        -> Ext (Posting Decimal Debit)
        -> Ledger l ()

instance CanDebit (Account Debit) where
  debit (DAccount {..}) p = do
      appendIOList debitAccountPostings p

instance CanDebit (Account Free) where
  debit (FAccount {..}) p = do
      appendIOList freeAccountDebitPostings p

instance CanCredit (Account Credit) where
  credit (CAccount {..}) p = do
      appendIOList creditAccountPostings p

instance CanCredit (Account Free) where
  credit (FAccount {..}) p = do
      appendIOList freeAccountCreditPostings p

instance CanCredit (FreeOr Credit Account) where
{'fraction_non_alphanumeric': 0.08196170641585489, 'fraction_numerical': 0.0, 'mean_word_length': 3.6677115987460813, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5171845', 'n_tokens_mistral': 955, 'n_tokens_neox': 924, 'n_words': 284}