haskell 无法将预期类型“Text”与实际类型“Data.MonoTraversable.Element mono0”匹配类型变量“mono0 "不明确

14ifxucb  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(109)

我尝试创建html节点,但遇到此错误:

Web/View/HardwareVendors/Show.hs:7:33
    • Couldn't match expected type ‘Text’
                  with actual type ‘Data.MonoTraversable.Element mono0’
      The type variable ‘mono0’ is ambiguous
    • In the second argument of ‘forEach’, namely ‘renderInput’
      In the first argument of ‘toHtml’, namely
        ‘((forEach hardwareVendor.required_fields) renderInput)’
      In the expression:
        toHtml ((forEach hardwareVendor.required_fields) renderInput)
  |
7 |     html ShowView { .. } = [hsx|
  |                                 ^...

字符串
相关源代码:

module Web.View.HardwareVendors.Show where
import Web.View.Prelude

data ShowView = ShowView { hardwareVendor :: HardwareVendor }

instance View ShowView where
    html ShowView { .. } = [hsx|
        {breadcrumb}
        <h1>{hardwareVendor.name}</h1>
        <form action="{hardwareVendor.getUrl}" method="get">
            -- required_fields is a Text[] postgres column
            {forEach hardwareVendor.required_fields renderInput}
            <input type="submit" value="Submit">
        </form>
    |]
        where
            breadcrumb = renderBreadcrumb
                            [ breadcrumbLink "HardwareVendors" HardwareVendorsAction
                            , breadcrumbText "Show HardwareVendor"
                            ]
renderInput :: Text -> Html
renderInput field = [hsx|
    <label for="{field}">{field}</label>
    <input type="text" id="{field}" name="{field}" required>
    <br>
|]


这里有一些额外的填充字,因为堆栈溢出验证是愚蠢的。这里有一些额外的填充字,因为堆栈溢出验证是愚蠢的。

g0czyy6m

g0czyy6m1#

假设这是一个正常的IHP数据库记录,则hardwareVendor.required_fields应该是hardwareVendor.requiredFields,因为IHP字段始终是驼峰式大小写

相关问题