PureScriptのRow型
「fieldの集合を表す型」と考えれば良さそう
e.g. (name::String, age::Int)
順序付けられていないCollection
順序を持たないので、 x:xs
のような「先頭を取ってくる」といった処理ができない
labelの重複も許す
用語を以下のように設定したい
Row
Row型のこと
つまり、kindが Type -> Type
な型
つまり、まだ何の型変数も適用されていないRow
row, rows、あるいは Row Type
kindが Row Type
な型
0個以上のfieldの集合
rowとrowsは、fieldの個数が複数あることを明示したいときに雰囲気で使い分ける
ちなみに、
Type
は具体化されていない型のことであって、
Row Int
とかは「rows」に含めない

field
hoge :: String
や hoge :: "piyo"
のような組
「propertyの名前」と、「property」の組
ちょっと雑だけど

label
propertyの名前
{hoge::String}
というときの hoge
上のRowとrowsの違いは、
関数の文脈における、 f
と f(x)
の差と同じような感じ
関数そのもののことを言っているのか、関数を適用した結果のことを言っているのかを区別して表記したい
じゃないと混乱する

文脈でだいたい分かるが、この辺の概念を理解してないときに混乱した
kind
purs(hs)data Row :: Type -> Type
kindは実際こうなのだが、これをあまり意識しすぎないほうが良い気もする

「Recordのfieldで使うんだな~」ぐらいに見ておくのがわかりやすい
syntax
0個以上のfieldを ()
で括れば Row Type
になる
具体例
以下の型のkindはすべて Row Type
(s :: String)
(s :: String, b :: Boolean)
(s :: String, s :: Boolean)
名前の重複ok
() :: Row Type
0個のfieldを持つrows
型シグネチャを書かないとerrorになる
(m :: Maybe)
のkindは Row (Type -> Type)
| r
の r
はRow型
e.g. type Lang r = { language :: String | r }
この | r
として書かれた r
はrows
だから↑に対してのkindを見ると以下のようになる
purs> :k Lang (b :: Boolean)
Type
> :k Lang -- これなんでerrorなるん???
Error
> :k Lang Int -- r はrowでないといけない
Error
使い所があるのか知らんが、Rowに対してRowを取る型も定義できる
e.g. type A r = ( s :: String | r )
Rowを適用した結果Rowになる
purs> :k A (b::Boolean)
Row Type
> :k A -- これなんでerrorなるん?
Error
:k A
は、 Row Type -> Row Type
になりそうだけどerrorになる
ちなみにこういう書き方もできるっぽい
purs:k (s::String | (b::Boolean))
Row Type
開いたRow型
purs(hs)> type R3 r = ( name :: String, age :: Number | r )
> :k R3 (hoge::Boolean)
Row Type
> :k R3 -- Error
> :k R3 Int -- Error
> :k R3 R1
Row Type
labelの重複を許す
purs(hs)type M = ( hoge :: String, hoge :: Int )
p = { hoge: "hoge", hoge: 1 } :: Record M -- Error (なんで???)
重複したlabelを持つrowをできる
Row Int
のようにして表記することはほぼなさそう
見たこと無い

でもこれのkindを調べることは出来る
kindは Type
なので、これをRecordに適用するなどはできない
ここの歪さがListとアナロジーできない点な気がする
関連Modules
Row型を扱うための型クラス集
眺めてるとRowのできることがなんとなくわかったりわからなかったりする

Row型を使ったValidationの例
ちょっと古いかも
Row
型は昔(いつ
#?? )は
#
という記号で表現されていた
kindを調べると # Type
と表示されていた
現在は Row Type
古い記事を見ると # Type
と書いているものもある
v0.14.2現在はdeprecatedになっており、警告が出る
Row型の使いみちは、RecordとEff
だったらしいが、今はEffは存在しないので、Recordでしか使わないはず
関連
参考
高度なものもありあまり読めてないけど
