diff --git a/.gitignore b/.gitignore index 546c812..1a311f5 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ cabal.project.local~ .idea *.iml cabal.config +out/ diff --git a/README.md b/README.md index 71eec76..f3a6126 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ strategyDouble n = 2*n -- now we define a context that applies a function of type Num a => a -> a to a list of a's: context :: Num a => (a -> a) -> [a] -> [a] context f l = map f l --- according to the rules of currying this can be abbreviated to: +-- using point-free notation this can be written as: context = map ``` The `context` function uses higher order `map` function (`map :: (a -> b) -> [a] -> [b]`) to apply the strategies to lists of numbers: @@ -1127,6 +1127,151 @@ So the Monoid type class definition forms a *template* where the default impleme ## TBD: Factory -> Function Currying + + + ## Conclusions > Design patterns are reusable abstractions in object-oriented software. > However, using current mainstream programming languages, these elements can only be expressed extra-linguistically: as prose,pictures, and prototypes. diff --git a/src/Builder.hs b/src/Builder.hs index 162ee2f..bb03223 100644 --- a/src/Builder.hs +++ b/src/Builder.hs @@ -9,21 +9,22 @@ data BankAccount = BankAccount { , interestRate :: Double } deriving (Show) -defaultAccount :: Int -> BankAccount -defaultAccount i = BankAccount i "" "" 0 0 +buildAccount :: Int -> BankAccount +buildAccount i = BankAccount i "Dummy Customer" "London" 0 0 builderDemo = do - putStrLn "Builder -> ???" - let acc1 = BankAccount { - accountNo = 1234 - , name = "Marjin" - , branch = "Reikjavik" - , balance = 1000 - , interestRate = 2.5 - } - print acc1 - let acc2 = defaultAccount 4711 - print acc2 - let acc3 = acc2 {name="Hans Mejer", branch="London", balance=10000} - print acc3 + putStrLn "Builder -> record syntax, smart constructor" + let account = buildAccount 1234 + print account + let account1 = account {name="Marjin Mejer", branch="Paris", balance=10000, interestRate=2} + print account + + let account2 = BankAccount { + accountNo = 5678 + , name = "Marjin Mejer" + , branch = "Reikjavik" + , balance = 1000 + , interestRate = 2.5 + } + print account2 \ No newline at end of file