PureScript(_)
PureScriptRecord使
Pattern Matching
point-free style
mrsekut





_
_





> double = (2 * _)
> dboule 10
20
> double n = n * 2
ps double = (*2) mrsekut



_ Record
{ x: _ } 1
> { x: _ } :: a. a -> { x :: a }
\a -> { x: a }
> f1 = { x: _ }
> f1 1
{ x: 1 }
> f2 = {x:_, y: "hoge"}
> f2 "piyo"
{ x: "piyo", y: "hoge" }
_
> f3 = { x:_, y: _ }
> f3 1 2
{ x: 1, y: 2 }



_ Record
x field
> :t _.x :: a r. { x :: a | r } -> a
> g1 = _.x
> g1 { x: 10, y: 100 }
10
> g2 = _.x.z
> g2 { x: { z:2 }, y: 100 }
2




Record
record x field 42
> :t _ { x = 42 } :: r a. { x :: a | r } -> { x :: Int | r }
HalogenhandleAction()mrsekut
> :t _ { x = _ } :: a r v. { x :: v | r } -> a -> { x :: a | r }
> u = _ { x = _ }
> u { x:100 } 200
{ x: 200 }



if使
> :t if _ then Just 42 else Nothing
Boolean -> Maybe Int
> b = if _ then Just 42 else Nothing
> b true
Just 42


switch使
f :: Int -> String
f = case _ of
0 -> "None"
1 -> "One"
_ -> "Some"
f :: Int -> String
f n = case n of
0 -> "None"
1 -> "One"
_ -> "Some"
case .. of 使
g :: Int -> Int
g x = x + 10
f :: Int -> String
f = case g _ of
0 -> "None"
...
<#>


HalogenhandleAction使
handleAction :: Action -> H.HalogenM State Action () output m Unit
handleAction = case _ of
SetValue v -> H.modify_ _ { value = v }
handleAction :: Action -> H.HalogenM State Action () output m Unit
handleAction action = case action of
SetValue v -> H.modify_ \st -> st { value = v }