私はいくつかのコードを見直していて、次の宝石に出くわしました。これは、pointfree
出力のコピーアンドペーストであると思います:
(私は、以下が通常よりも適切だと思いましたfoo
/bar
この特定の質問について:P)
import Control.Monad (liftM2)
data Battleship = Battleship { x :: Int
, y :: Int
} deriving Show
placeBattleship :: Int -> Int -> Battleship
placeBattleship x' y' = Battleship { x = x', y = y' }
coordinates :: Battleship -> (Int, Int)
coordinates = liftM2 (,) x y
(i)coordinates b = (x b, y b)
から
(ii)に単純化するために必要な手順を説明してくれる人は親切でしょうかcoordinates = liftM2 (,) x y
? 特に、背景にモナドが潜んでいることにさえ気づいていなかったので
、 の使用については少し混乱しています。liftM2
(i) は次のように表すこともできますがcoordinates s = (,) (x s) (y s)
、どこでどのように進めればよいかわかりません。
PS以下は、それがからだと思われる理由ですpointfree
(出力はからGHCI
であり、:pl
にエイリアスされていpointfree
ます):
λ: :pl coordinates s = (x s, y s)
coordinates = liftM2 (,) x y