jaspervdj / digestive-functors

A general way to consume input using applicative functors
149 stars 71 forks source link

subViews ignores viewContext #41

Closed davidsd closed 12 years ago

davidsd commented 12 years ago

In its current implementation, subViews ignores viewContext, so that repeated calls to subViews only ever retrieve the children of the top level of a view. Consequently, it doesn't play nicely with subView. For example, consider

data Bar = Bar Foo Foo
data Foo = Foo Int Int

barForm :: Monad m => Form Text m Bar
barForm = Bar <$> "foo1" .:  fooForm <*> "foo2" .: fooForm

fooForm :: Monad m => Form Text m Foo
fooForm = Foo <$> "int1" .: intForm <*> "int2" .: intForm

intForm :: Monad m => Form Text m Int
intForm = stringRead "Not a number" (Just 0)

I would like to be able to call subViews (subView "foo1" view) and obtain views with contexts ["foo1", "int1"] and ["foo1", "int2"]. However, instead I get:

[View "barForm" ["foo1","foo1"] App (Nothing)
  Map _
    App (Just "foo1")
      Map _
        Pure (Just "int1") (Text "0")
      Map _
        Pure (Just "int2") (Text "0")
  App (Just "foo2")
    Map _
      Pure (Just "int1") (Text "0")
    Map _
      Pure (Just "int2") (Text "0")
 [] [] Get,View "barForm" ["foo1","foo2"] App (Nothing)
  Map _
    App (Just "foo1")
      Map _
        Pure (Just "int1") (Text "0")
      Map _
        Pure (Just "int2") (Text "0")
  App (Just "foo2")
    Map _
      Pure (Just "int1") (Text "0")
    Map _
      Pure (Just "int2") (Text "0")
 [] [] Get]

These contexts are now incorrect, and give errors when I try to do things with them. Is this the desired behavior for subViews?

jaspervdj commented 12 years ago

This is definitely a bug, thanks for reporting!