在Snap Framework上,Snaplets通过一个基于构成部分的界面将功能纳入其他Snaplets: 主要网络应用是Snaplet,通过传统“has-a”关系提及其他Snaplets,而次Snaplets则可以参考其他Snaplets。
在研究各种Snaplet的执行情况时,我看到了将Snaplet带入母Snaplet的不同模式。 具体地说:
Kind of reference. The Snaplet implementation assumes that a specific kind of relation to the parent Snaplet is present. This is enforced via the Reference method used (see below).
明确提及:
data MySnaplet = MySnaplet { subSnaplet :: Snaplet SubSnaplet }
A relative lens:
data MySnaplet = MySnaplet { _subSnaplet :: Snaplet SubSnaplet } subSnaplet :: Lens MySnaplet SubSnaplet subSnaplet = lens _subSnaplet $ a b -> a { _subSnaplet = b }
参考方法。 《Snaplet》的实施通过接口强制执行,即采用某种特定方式获取Snaplet数据,而不同的Snaplet实施则使用不同的方法。 Snaplet假设:
- The data is present in a
MonadState
every time a function that manipulates the Snaplet is called. - The data is present in a
MonadState
and wrapped in aSnaplet
wrapper. - There is a class+instance like
instance HasSubSnaplet MySnaplet
that has a function for getting the Snaplet data out ofMySnaplet
provided that aMySnaplet
is in aMonadState
at the point of calling the function. - The function in 3. has type
MySnaplet -> Snaplet SubSnaplet
instead. - There is a class+instance like in 3. that provides a
Lens MySnaplet (Snaplet SubSnaplet)
. - The class+instance requires a
Lens (Snaplet MySnaplet) (Snaplet SubSnaplet)
. - The class+instance assumes that
MySnaplet
is the "top Snaplet" of the application, and requires an absolute lens/reference, such thatMySnaplet
must be theb
in aMonadSnaplet
.
- The data is present in a
如我所知,如果Snaplet读一读,参考性1即有意义。 如果Snaplet需要改变的话,是有意义的。
Further, having a class for the method makes sense when MySnaplet
can have only one SubSnaplet
and no more, and having an absolute reference might make sense for things like databases, that cannot possibly be configured as a component, given that only the top Snaplet has access to credentials and what not. However, making this assumption as a Snaplet writer might be fallacious, and there would be no disadvantages to using a relative references instead.
There s one proglem, though: Existing Snaplets on Hackage do not fit with these assumptions that I make; all of the methods described above are used seemingly at random and in all kinds of circumstances. Also, I see no advantage/disadvantage to some of the other aspects described above (Such as requiring a Snaplet
wrapper, or not).
To me, reference kind 2. and one of methods 1, 2, 5 or 6 seem to make the most sense under all circumstances, and I see no reason why there s not a consensus on only using e.g. (2, 1) all the time.
因此:
www.un.org/Depts/DGACM/index_spanish.htm 作为Snaplet作家,在撰写新的Snaplet(假定其具有一般目的)和时,应优先考虑这种方法。
www.un.org/Depts/DGACM/index_spanish.htm 为什么所有存在Snaplets的人都没有使用同样的参考方法(见核心<代码>nap)。 采用不同方法的包件?