Haskell:wxHaskell 中的网格
有人可以逐行解释一下这段代码的作用吗?
如何准确理解声明的第一行? [Prop (Grid ())] 是什么意思?
谢谢你的帮助
gridCtrl :: Window a -> [Prop (Grid ())] -> IO (Grid ())
gridCtrl parent props
= feed2 props 0 $
initialWindow $ \id rect -> \props flags ->
do g <- gridCreate parent id rect flags
gridCreateGrid g 0 0 0
set g props
return g
Could someone explain me what this code does line by line ?
how t ounderstand excactly first line with declaration ?
what does it mean: [Prop (Grid ())]?
thanks for help
gridCtrl :: Window a -> [Prop (Grid ())] -> IO (Grid ())
gridCtrl parent props
= feed2 props 0 $
initialWindow $ \id rect -> \props flags ->
do g <- gridCreate parent id rect flags
gridCreateGrid g 0 0 0
set g props
return g
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 wxHaskell 中,控件具有可以读取或更改的附加属性。 [Prop (Grid ())] 节可以理解为“任何 Grid 类型的属性列表”。
这是 wxHaskell 处理 wxWidgets 库(它所构建的库)是面向对象这一事实的方式。 Grid () 实际上意味着“Grid 派生的继承层次结构中的任何内容” - 即 Grid、ScrolledWindow、Panel、Window、EvtHandler、wxObject(如果您从 http://wxhaskell.sourceforge.net/doc/Graphics-UI-WXCore-WxcClassTypes.html#204< /a>)
当您查看控件(例如ListCtrl)的文档时,您会发现它被报告为具有一组属性和实例。基本上,您可以使用适用于网格层次结构的那些。例如,Grid 派生自ScrolledWindow,因此您可以使用:
您按如下方式使用这些属性,例如
逐行,代码如下所示:
使代码最难阅读的部分是feed2函数,并且代码是以“$”样式编写的,以便为 feed2 提供正确的参数。我上面的解释应该足够了,但是如果你想了解细节,请理解 feed2 只是由倒置函数应用程序组成,
然后用括号替换“$”应用程序。这看起来不那么可爱,但更容易阅读。
In wxHaskell, controls have attached properties which can be read or changed. The stanza [Prop (Grid ())] can be understood as "a list of properties for any Grid type".
This is wxHaskell's way of dealing with the fact that the wxWidgets library, which it is built on, is object-oriented. Grid () actually means "anything in the inheritance hierarchy from which Grid derives" - i.e. Grid, ScrolledWindow, Panel, Window, EvtHandler, wxObject (you can follow this through if you start at at http://wxhaskell.sourceforge.net/doc/Graphics-UI-WXCore-WxcClassTypes.html#204)
When you look at the documentation of a Control (e.g. ListCtrl) you will find that it is reported as having a set of Attributes and Instances. Basically, you can use those which apply to the hierarchy for Grid. For example, Grid derives from ScrolledWindow, so you can use:
You use these properties as follows, e.g.
Line by line, the code reads something like the following:
The part which makes the code hardest to read is the feed2 function, and that fact that the code is written in '$' style to provide the correct parameters to feed2. My slightly hand-waving explanation above should be enough, but if you want to understand the details, understand that feed2 is just composed inverted function application
then replace the '$' applications with parentheses. This doesn't look as cute, but is easier to read.