PureScriptの(_)で関数を作る
一貫性があるので全ての具体例を見なくてもノリがわかると思う

_
が関数を作る
_
の個数分の引数を取る関数を作る
以下、具体例
関数
spago> double = (2 * _)
> dboule 10
20
以下と同じ
psでは
double = (*2)
とは書けない

_
でRecordを作成する関数を作る
{ x: _ }
自体が1引数関数になっている
spago> { x: _ } :: ∀ a. a -> { x :: a }
これは以下と同じ
spago> f1 = { x: _ }
> f1 1
{ x: 1 }
> f2 = {x:_, y: "hoge"}
> f2 "piyo"
{ x: "piyo", y: "hoge" }
_
の数だけ引数を取る
spago > f3 = { x:_, y: _ }
> f3 1 2
{ x: 1, y: 2 }
_
でRecordのアクセッサーを作る
x
fieldにアクセスする関数
spago> :t _.x :: ∀ a r. { x :: a | r } -> a
spago> g1 = _.x
> g1 { x: 10, y: 100 }
10
ネストしててもいい
spago> g2 = _.x.z
> g2 { x: { z:2 }, y: 100 }
2
Recordを更新する関数を作る
受け取ったrecordの x
fieldを 42
に更新する関数
spago> :t _ { x = 42 } :: ∀ r a. { x :: a | r } -> { x :: Int | r }
HalogenのhandleActionの中でよく見る形(後述)

より一般化する
spago> :t _ { x = _ } :: ∀ a r v. { x :: v | r } -> a -> { x :: a | r }
> u = _ { x = _ }
> u { x:100 } 200
{ x: 200 }
if式に使う
spago> :t if _ then Just 42 else Nothing
Boolean -> Maybe Int
> b = if _ then Just 42 else Nothing
> b true
Just 42
switch式に使う
purs(hs)f :: Int -> String
f = case _ of
0 -> "None"
1 -> "One"
_ -> "Some"
以下と同じ
purs(hs)f :: Int -> String
f n = case n of
0 -> "None"
1 -> "One"
_ -> "Some"
case .. of
の中に関数があると使えない
これだとエラーになる↓
purs(hs)g :: Int -> Int
g x = x + 10
f :: Int -> String
f = case g _ of
0 -> "None"
...
地味に一貫性がない
<#>
と組み合わせる
良い実用例
purs(hs)handleAction :: Action -> H.HalogenM State Action () output m Unit
handleAction = case _ of
SetValue v -> H.modify_ _ { value = v }
以下と同じ
purs(hs)handleAction :: Action -> H.HalogenM State Action () output m Unit
handleAction action = case action of
SetValue v -> H.modify_ \st -> st { value = v }
参考