Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying a Singleton field #144

Open
cimmanon opened this issue Jun 13, 2017 · 1 comment
Open

Querying a Singleton field #144

cimmanon opened this issue Jun 13, 2017 · 1 comment

Comments

@cimmanon
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants