View monad_transformers.md

Monads allow us to build computations that have effects. However, in "real code", we often need to be able to use several effects at once. This is what monad transformers allow us to do.

A monad transformer modifies the behavior of the underlying monad. It modifies the behavior in that it adds teh effect of the base monad to the inner monad.

Some examples:

  1. The StateT monad transformer adds mutable state to the underlying monad.
View a.hs
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Handler.ExpenseFile where
import Import
import Handler.Expense (expenseFileForm)
import Data.Csv (decodeByName)
import qualified Data.ByteString as B
postExpenseFileR :: Handler Html
View bitestring
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Handler.ExpenseFile where
import Import
import Handler.Expense (expenseFileForm)
import Data.Csv (decodeByName)
postExpenseFileR :: Handler Html
postExpenseFileR = do
View getSum.hs
calculateReport :: Budget -> [Transaction] -> Report
calculateReport budget transactions =
Report
{ budgetProfit = budgetProfit'
, netProfit = netProfit'
, difference = netProfit' - budgetProfit'
}
where
budgetProfit' = budgetIncome budget - budgetExpenditure budget
netProfit' = getSum (foldMap asProfit transactions)
View separate.hs
-- WORKING CODE
getCategoryR :: Handler Html
getCategoryR = do
allCategories <- runDB $ selectList [] [] :: Handler [Entity Category]
let badges = []
categoriesWithExpenseCount <- categoriesWithExpenseCount
(formWidget, formEnctype) <- generateFormPost categoryForm
defaultLayout $(widgetFile "category")
categoriesWithExpenseCount :: Handler [(Entity Category, E.Value Int)]
View foldr.hs
-- foldr is meant to encapsulate the following pattern:
-- f [] = v
-- f (x:xs) = x # f xs
-- where # is an operator applied to the head of the list and recursively processing the tail
-- Using sum:
-- sum [] = 0
-- sum (x:xs) = x + sum xs
-- Therefore, sum = foldr (+) 0
View fromIntegral.md

Hello folks, I have the following code, and I am having trouble understanding how fromIntegral is functioning:

avgDb :: [DatabaseItem] -> Double
avgDb dataBase = dividend / divisor
                 where dividend = fromIntegral $ sumDb dataBase
                       divisor = fromIntegral $ length $ filterDbNumber dataBase

Note that sumDb :: [DatabaseItem] -> Integer and filterDbNumber :: [DatabaseItem] -> [Integer].

View unverified_error.hs
-- Page 12 on the 0.12.0-screen version of the book
-- You start step 2 with the following lambda:
(\x.\y.\z.xy(yz))(\m.\n.\m)(\p.p)
-- You then reduce it, in step 3 to the following:
(\y.\z(\m.\n.\m)z(yz))(\p.p)
-- I believe that this reduce is missing a period after the first z, and instead should read like so:
(\y.\z.(\m.\n.\m)z(yz))(\p.p)
View keybase.md

Keybase proof

I hereby claim:

  • I am stevenxl on github.
  • I am stevenxl (https://keybase.io/stevenxl) on keybase.
  • I have a public key whose fingerprint is 9520 A429 3F63 17DD 47A8 7765 92CD EE68 A369 3DFA

To claim this, I am signing this object:

View process_registry_v06.exs
defmodule ProcessRegistry do
import Kernel, except: [send: 2]
use GenServer
# Client API #
def start_link do
GenServer.start_link(__MODULE__, nil, name: :registry)
end