English 中文(简体)
D. 参考次微秒
原标题:Preferred method for referencing sub-Snaplets
  • 时间:2012-01-13 15:10:20
  •  标签:
  • haskell

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).

    1. 明确提及:

      data MySnaplet = MySnaplet { subSnaplet :: Snaplet SubSnaplet }
      
    2. 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假设:

    1. The data is present in a MonadState every time a function that manipulates the Snaplet is called.
    2. The data is present in a MonadState and wrapped in a Snaplet wrapper.
    3. There is a class+instance like instance HasSubSnaplet MySnaplet that has a function for getting the Snaplet data out of MySnaplet provided that a MySnaplet is in a MonadState at the point of calling the function.
    4. The function in 3. has type MySnaplet -> Snaplet SubSnaplet instead.
    5. There is a class+instance like in 3. that provides a Lens MySnaplet (Snaplet SubSnaplet).
    6. The class+instance requires a Lens (Snaplet MySnaplet) (Snaplet SubSnaplet).
    7. The class+instance assumes that MySnaplet is the "top Snaplet" of the application, and requires an absolute lens/reference, such that MySnaplet must be the b in a MonadSnaplet.

如我所知,如果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)。 采用不同方法的包件?

最佳回答

TLDR; 大部分时间可能希望使用,功能和相对镜头。

使用HasSubSnaplet类类别是一种完全可选择的模式,可减少“以亚Snaplet”类的浮体,因为如果其认为有不止一种次次低级动物,那么这种方式就可减少。 我们选择这样做,是因为海卫会认为船舶是天花板的,并且为使用者树立了这种模式的榜样。

由于这类类别完全是选择性的,而且大致是宽松的,因此,其余部分的答案是,没有哪类类别,则侧重于什么。

普遍定期审议机制的意图是,你使用能打上Snaplet数据类型内容的镜头(不是“解释性参考资料”)进入贵国。 这是因为,在申请处理过程中的突变状态是我们希望Snaplets提供的基本能力。 大部分情况下,我们打算使用<代码>Snaplet,作为不透明的总结,即终端用户除国家类型外,不需要接触。 正因如此,莫德邦法庭在没有Snaplet包裹的情况下直接接触你。

尽管如此,有四个基本准入模式。 参看以下网址:http://hackage.haskell.org/parages/archive/snap/07/c/html/Snap-Snaplet.html MonadSnaplet category 。

with     :: Lens     v       (Snaplet v ) -> m b v  a -> m b v a
withTop  :: Lens     b       (Snaplet v ) -> m b v  a -> m b v a
with     :: Lens (Snaplet v) (Snaplet v ) -> m b v  a -> m b v a
withTop  :: Lens (Snaplet b) (Snaplet v ) -> m b v  a -> m b v a

头两个功能所体现的透镜模式是,由带有TemplateHaskell的成套数据自动生成的,是最自然使用的。 因此,这是建议的格局。 (如果名称较短,非价格。) <与的区别在于。 采用相对透镜和<代码>。 采取绝对原则。 我使用相对镜头的多数时间。 但是,我们希望允许使用绝对镜子,因为我可以想象,如果一个神父可能需要接受另一个神父提供的东西,但不是目前食堂的后代,就会出现复杂的应用。

Occasionally there are situations where you want to be able to have an identity lens. That requires a Lens (Snaplet a) (Snaplet b). So the second two primed functions are analogous to the first two except they take this kind of lens.

问题回答

暂无回答




相关问题
Euler Problem in Haskell -- Can Someone Spot My Error

I m trying my hand at Euler Problem 4 in Haskell. It asks for that largest palindrome formed by multiplying two three-digit numbers. The problem was simple enough, and I thought my Haskell-fu was up ...

How does foldr work?

Can anybody explain how does foldr work? Take these examples: Prelude> foldr (-) 54 [10, 11] 53 Prelude> foldr (x y -> (x+y)/2) 54 [12, 4, 10, 6] 12.0 I am confused about these executions....

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Problem detecting cyclic numbers in Haskell

I am doing problem 61 at project Euler and came up with the following code (to test the case they give): p3 n = n*(n+1) `div` 2 p4 n = n*n p5 n = n*(3*n -1) `div` 2 p6 n = n*(2*n -1) p7 n = n*(5*n -3)...

Ways to get the middle of a list in Haskell?

I ve just started learning about Functional Programming, using Haskel. I m slowly getting through Erik Meijer s lectures on Channel 9 (I ve watched the first 4 so far) and in the 4th video Erik ...

haskell grouping problem

group :: Ord a => [(a, [b])] -> [(a, [b])] I want to look up all pairs that have the same fst, and merge them, by appending all the list of bs together where they have the same a and discarding ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?