4.5から
Option<string> とかける
string option でもいいらしい
takezaki.icon 小文字でもいいのかな
良さそう
option<string> や string Option という書き方も合法っぽい
大文字小文字の区別は必要だけど、自作した型パラメータをとる型でも書き方ができる
'T option Type
Namespace: FSharp.Core
Assembly: FSharp.Core.dll
Abbreviation For: Option<'T>
Result<'Success,'Failure>
Haskell の Either みたいに Left Right の順番じゃないので注意が必要
('a, 'b) result は deprecated
--mlcompatibility
unit があると副作用があるかも
takezaki.icon IO とかないんだっけ
Ocaml とかの語族にはないらしい(純粋関数型ではないので)
ドメインモデリングでは、常に list 型を使用することをお勧めします。
ほんまか?
第5章 型によるドメインモデリング
ドメインモデル(省略を一部埋めたやつ)
code:ドメインモデル
context: Order-Taking
// ----------------------
// 単純型
// ----------------------
// 製品コード
data ProductCode = WidgetCode OR GizmoCode
data WidgetCode = string starting with "W" then 4 digits
data GizmoCode = string starting with "G" then 3 digits
// 注文数量
data OrderQuantity = UnitQuantity OR KilogramQuantity
data UnitQuantity = integer between 1 and 1000
data KilogramQuantity = decimal between 0.05 and 100.00
// ----------------------
// 注文のライフサイクル
// ----------------------
// ----- 未検証の状態-----
data UnvalidatedOrder =
UnvalidatedCustomerInfo
AND UnvalidatedShippingAddress
AND UnvalidatedBillingAddress
AND list of UnvalidatedOrderLine
data UnvalidatedOrderLine =
UnvalidatedProductCode
AND UnvalidatedOrderQuantity
// ----- 検証済みの状態-----
data ValidatedOrder =
ValidatedCustomerInfo
AND ValidatedShippingAddress
AND ValidatedBillingAddress
AND list of ValidatedOrderLine
data ValidatedOrderLine =
ValidatedProductCode
AND ValidatedOrderQuantity
// ----- 価格計算済みの状態-----
data PricedOrder =
ValidatedCustomerInfo
AND ValidatedShippingAddress
AND ValidatedBillingAddress
AND list of PricedOrderLine
AND AmountToBill
data PricedOrderLine =
ValidatedOrderLine
AND LinePrice
// ----- 出力イベント-----
data OrderAcknowledgmentSent = ...
data OrderPlaced = ...
data BillableOrderPlaced =
OrderId
AND BillingAddress
AND AmountToBill
// ----------------------
// ワークフロー
// ----------------------
workflow "Place Order" =
input: UnvalidatedOrder
output (on success):
OrderAcknowledgmentSent
AND OrderPlaced (to send to shipping)
AND BillableOrderPlaced (to send to billing)
output (on error):
InvalidOrder
// etc
code:fs
type UnitQuantity = UnitQuantity of int
[<Struct>] がないと
code:c
struct UnitQuantity { int*; };
データ指向設計
kakkun61.icon AoS and SoA (array of structures (AoS), structure of arrays (SoA)) どっちにするか考えるのに近いかな
code:fs
type UnitQuantities = UnitQuantities of int[]
kakkun61.icon type UnitQuantities = UnitQuantity[] の方がいいんじゃないのという気持ち
エンティティに対する等値性の実装
Equals の override はオブジェクト指向っぽさが強い
次回 5.8 から