我没用过的 WX 库,内部似乎使用了奇怪的回调或延续传递样式。这个阴影props
以一种令人困惑的方式,让我重命名那个傻瓜:
staticText1 :: Window a -> [Prop (StaticText ())] -> IO (StaticText ())
staticText1 parent propsTopLevel
= feed2 propsTopLevel 0 $
initialWindow $ \id rect ->
initialText $ \txt -> \propsParam flags ->
do t <- staticTextCreate parent id txt rect flags
set t propsParam
return t
没有 ($) 我可以使用括号:
staticText2 :: Window a -> [Prop (StaticText ())] -> IO (StaticText ()) staticText2 parent propsTopLevel = feed2 propsTopLevel 0 (initialWindow (\id rect -> initialText (\txt -> \propsParam flags -> do t <- staticTextCreate parent id txt rect flags set t props return t)))
诸如此类的 lambda\text -> \props flags ->
可以命名为:
staticText3 :: Window a -> [Prop (StaticText ())] -> IO (StaticText ())
staticText3 parent propsTopLevel = initialWindow myWindow propsTopLevel 0
where makeWindow id rect = initialText myText
where myText txt propsParam flags = do
t <- staticTextCreate parent id txt rect flags
set t propsParam
return t
在staticText3
我使用嵌套词法范围作为参数名称。让我更明确一点:
staticText4 :: Window a -> [Prop (StaticText ())] -> IO (StaticText ())
staticText4 = makeWindowTextStatic where
makeWindowTextStatic parent propsTopLevel = initialWindow (makeTextStatic parent) propsTopLevel 0
makeTextStatic parent id rect = initialText (makeStatic parent id rect)
makeStatic parent id rect txt propsParam flags = do
t <- staticTextCreate parent id txt rect flags
set t propsParam
return t
这是否足够清楚以跟随流程?我还没有尝试去理解initialWindow
和initialText
他们自己。