digestive-functors icon indicating copy to clipboard operation
digestive-functors copied to clipboard

Querying a Singleton field

Open cimmanon opened this issue 7 years ago • 1 comments

I see functions for querying Text, Choice, Bool, and File via fieldInputText, etc., but there doesn't appear to be a function for querying a Singleton. I attempted to write one myself, but I'm a little baffled by the error I'm getting because I've basically just copied from the fieldInputText function.

fieldInputSingleton :: forall v a. T.Text -> View v -> a
fieldInputSingleton ref (View _ _ form input _ method) =
	queryField path form eval'
	where
		path = toPath ref

		eval' :: Field v b -> a
		eval' field = case field of
			Singleton x -> undefined
			--Singleton x -> evalField method [] (Singleton x)
			f -> error $ T.unpack ref ++ ": expected (Singleton _), " ++
				"but got: (" ++ show f ++ ")"

When I replace Singleton x -> undefined (line 79) with the one below it that's commented out, I get the following error:

src/Util/Digestive/Heist.hs:79:71:
    Could not deduce (b ~ a2)
    from the context (Monad m)
      bound by a pattern with constructor
                 View :: forall v a (m :: * -> *).
                         Monad m =>
                         T.Text
                         -> Path
                         -> FormTree Data.Functor.Identity.Identity v m a
                         -> [(Path, FormInput)]
                         -> [(Path, v)]
                         -> Method
                         -> View v,
               in an equation for `fieldInputSingleton'
      at src/Util/Digestive/Heist.hs:72:26-53
      `b' is a rigid type variable bound by
          the type signature for eval' :: Field v1 b -> a2
          at src/Util/Digestive/Heist.hs:77:26
      `a2' is a rigid type variable bound by
           the type signature for eval' :: Field v1 b -> a2
           at src/Util/Digestive/Heist.hs:77:26
    Relevant bindings include
      x :: b (bound at src/Util/Digestive/Heist.hs:79:35)
      field :: Field v1 b (bound at src/Util/Digestive/Heist.hs:78:23)
      eval' :: Field v1 b -> a2
        (bound at src/Util/Digestive/Heist.hs:78:17)
    In the first argument of `Singleton', namely `x'
    In the third argument of `evalField', namely `(Singleton x)'

What am I missing?

cimmanon avatar Jun 13 '17 14:06 cimmanon

https://stackoverflow.com/questions/51022131/how-do-i-get-the-form-value-from-a-singleton-field-in-digestive-functors

Stuck on this too...

chrissound avatar Jun 25 '18 21:06 chrissound