Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let us look at the type of <code>areq</code></p> <pre><code>areq :: (RenderMessage master msg, RenderMessage master FormMessage) =&gt; Field sub master a -&gt; FieldSettings msg -&gt; Maybe a -&gt; AForm sub master a </code></pre> <p>So the <code>areq</code> function doesn't expect a <code>Text</code> value as its second parameter, it expects a <code>FieldSettings msg</code>. So what is the reason that it works when you write "Name" in your source code?</p> <p>Looking up the documentation for <code>FieldSettings</code> in <a href="http://hackage.haskell.org/packages/archive/yesod-form/0.3.1/doc/html/Yesod-Form-Types.html#t%3aFieldSettings" rel="nofollow">the documentation for yesod-forms</a> we see that it is a datatype that has an <code>IsString</code> instance. Looking at the specific instance in <a href="http://hackage.haskell.org/packages/archive/yesod-form/0.3.1/doc/html/src/Yesod-Form-Types.html#FieldSettings" rel="nofollow">the source code</a> we see that:</p> <pre><code>instance (a ~ Text) =&gt; IsString (FieldSettings a) where fromString s = FieldSettings (fromString s) Nothing Nothing Nothing [] </code></pre> <p>So everytime you write a String in your source code (if the OverloadedStrings extension is enabled), the compiler will insert the contents of the fromString instance.</p> <p>However, you don't want to enter a String, but instead you want to create a FieldSettings from a <code>Text</code> value. Looking further we see that the first part of a <code>FieldSettings</code> is a <code>SomeMessage</code>, checking the <a href="http://hackage.haskell.org/packages/archive/shakespeare-i18n/1.0.0.2/doc/html/Text-Shakespeare-I18N.html" rel="nofollow">documentation yet again</a> and the <a href="http://hackage.haskell.org/packages/archive/shakespeare-i18n/1.0.0.2/doc/html/src/Text-Shakespeare-I18N.html#SomeMessage" rel="nofollow">source</a> we see that a <code>SomeMessage</code> can be created by using the <code>SomeMessage</code> constructor.</p> <pre><code>personForm :: Text -&gt; Html -&gt; MForm Handler (FormResult Person, Widget) personForm n1 = renderDivs $ Person &lt;$&gt; areq textField (FieldSettings (SomeMessage n1) Nothing Nothing Nothing []) Nothing </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload