『Domain Modeling Made Functional』
要は関数型言語でDDDする本
英語が平易で読みやすい


この本を読むためにF#の事前知識はどれほど必要か
4章で型の説明があるので「関数型言語」の知識はなくても耐えそうだが、
実際、関数型初見マンがこれぐらいの薄い説明で納得できるのかは微妙だと思う
関数型の経験があれば4章は不要レベル
今までF#のままメモってたが意味ない無いのでできるだけhsで書こう

ただ、F#でのこれって、HSでのどれだっけ?になる場合はF#書く
実装
F#
Haskell
F#
Elm
Rust
ReasonML
いっぱいあるのは良いけど本のものを完全に実装してない感じがある
Idris
この本の中で作ろうとしているものの要件のmemo
1章
これ、のちの型でワークフローを書くことの伏線になっているのか

ユビキタス言語
2章
インタビューの過程が説明されている
Domain Expertから学んだことをDSLで表現する
個々の値の上限・下限
ワークフローを型で定義
3章
関数指向のドメインモデルのためのアーキテクチャについて
この本特有の言葉
choice type
直和型、Union型のこと
Haskellのnewtypeと同じ
fsharptype ProductCode = ProductCode of string // `ProductCode`はユビキタス言語
// こう書いているのに近い. singleのunion型
type ProductCode =
| ProductCode of string
// 利用
let productCode = ProductCode 42
ユビキタス言語を活用するために、pritimive型を逐次simple typeにする
4章 Understanding Types
F#の超基本的な型の解説
型シグネチャとか、代数的データ型とか
関数型言語を少しでもしてたら既に知っているようなこと
ドメインでの処理の流れをそのまま型で表現しちゃえばいい
fsharptype PayInvoice =
UnpaidInvoid -> Payment -> Result<PaidInvoice, PaymentError>
未払い請求書
があり、 決済
が行われたら、 支払い済み請求書
になる
ディレクトリ構成の話
型用のファイルと関数用のファイルを分ける
ファイル内で書く順番によって使用できなかったりするので注意
5章 Domain Modeling with Types
ドメインモデルをF#の型で表現していく
この辺は

と同じことを言っている

A Question of Identity: ValueObject p.88
A Question of Identity: Entity p.89
Aggregate
6章 Integrity and Consistency in the Domain
この辺はもう、型のみで完結できる範囲を少し超えていたりする

trustedなDomainには、IntegrityとConsistencyの2つの側面がある
この2つに分ける必然性が微妙にわからない

日本のスターバックスのレジでの非同期的な処理を例にして説明している
7章 Modeling Workflows as Pipelines
>Part III Implementing the Model
8 Understanding Functions
FPの基本的なことの解説
高階関数
カリー化
F#もhsと同様に全ての関数はカリー化される
部分適用
p.154~の例って、
Int
を引数に取っているのに
0~6
しかmatchさせないことに触れてないけどそもそも嘘じゃない?例が良くない

Compositionは関数結合のこと
F#ではよく |>
を使う
ほぼ既知だったので軽く読み飛ばした

9 Implementation: Composing a Pipeline
最終的にはこういう感じで処理を書きたい
fslet placeOrder unvalidatedOrder =
unvalidated0rder
|> validateOrder
|> priceOrder
|> acknowledgeOrder
|> createEvents
7章までで、各stepの型を定義したので、ここから内部を実装していく
最終的に上のように連結したいが以下のような困難が出てくるので工夫が必要
副作用の扱い
前のoutputと次のinputが異なる
別の場所から引数を取ってこないといけないケースがある
etc.
9章で副作用を無視したDIについて、10章でinput/outputの乖離の問題を扱う?
この辺はsmart constructorをちゃんと作ろうな、という話を具体例を用いてしている
まだ各stepの定義をしているだけ
次のinputのために、outputを変換する手法は紹介されている
次のinputの引数を別の場所から取ってくる方法まだなので、そのままではcomposeできない
composeする方法
Injecting Dependencies
基本は、関数の引数に関数を渡すDIをする
場所によっては、カリー化でDIする
前の節を読んでないので、個々の関数がどういうものかを知らずに読んだ
要旨はわかった気がするが、前から順に読む時に再読しても良さそう

Testing Dependencies
前章の内容を前提としたtest
The Assembled Pipeline 187(3)
Wrapping Up 190(1)
10 Implementation: Working with Errors 191(30)
Result型を使ってerrorを扱う
起きうるErrorの種類が型で明示される
Using the Result Type to Make Errors 191(1)
Explicit
Working with Domain Errors 192(4)
Chaining Result-Generating Functions 196(7)
Using bind and map in Our Pipeline 203(2)
Adapting Other Kinds of Functions to the 205(4)
Two-Track Model
Making Life Easier with Computation 209(8)
Expressions
Monads and More 217(1)
Adding the Async Effect 218(2)
Wrapping Up 220(1)
11 Serialization
Domain Type, DTO, JSON等、間の変換をする
前と同様pipelineで
型の種類ごとのDTOの表現方法を解説している
12 Persistence
Pushing Persistence to the Edges 239(5)
Command-Query Separation 244(4)
Bounded Contexts Must Own Their Data 248(2)
Storage
Working with Document Databases 250(1)
Working with Relational Databases 251(11)
Transactions 262(1)
Wrapping Up 263(2)
13 Evolving a Design and Keeping It Clean 265(20)
Change 1 Adding Shipping Charges 266(4)
Change 2 Adding Support for VIP Customers 270(3)
Change 3 Adding Support for Promotion 273(7)
Codes
Change 4 Adding a Business Hours 280(1)
Constraint
Dealing with Additional Requirements 281(1)
Changes
Wrapping Up 282(1)
Wrapping Up the Book 283(2)
Index 285
著者の公演
書評