- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此时GHCJS编译失败postgresql-simple
包(参见 [ 1 ])。我想用 persistent
包生成数据库模型。我想知道是否可以使用 GHC 本身编译模型并在 GHCJS 源代码中重用由 Template Haskell 生成的代码?
我的问题已经有了解决方法,但这个问题仍然相关。我会把它打开几天,如果没有人回答如何使用 Template Haskell 生成的代码,我会关闭它。我已将生成的代码粘贴在底部。
更新:
thomie 建议我 -dth-dec-file
标志,可以在模型文件中写为语言编译指示,例如{-# OPTIONS_GHC -dth-dec-file #-}
.然后在运行 stack build
之后命令有一个文件 Model.th.hs
在 .stack-work/dist/<arch>/<cabal-version>/build/src
下文件夹。这个文件看起来像有效的 Haskell,但是 GHC 因为解析错误而拒绝它(见底部的代码)。但是,我找到了一种使用 GHCJS 编译模型的方法。我在 cabal 文件中添加了条件以删除 postgresql-simple
来自依赖项:
-- project.cabal
library
-- ...
if impl(ghcjs)
build-depends: persistent
, persistent-template
else
build-depends: persistent
, persistent-postgresql
, persistent-template
, postgresql-simple
由 Template Haskell 生成的代码(为了测试此代码,我将此文件复制到项目源文件夹中并在顶部添加了模块声明)
-- src/Model.hs:(16,1)-(17,54): Splicing declarations
instance Database.Persist.Class.PersistField.PersistField Manufacturer where
Database.Persist.Class.PersistField.toPersistValue
= \ ent_a9ov
-> (Database.Persist.Types.Base.PersistMap
GHC.Base.$
(GHC.List.zip
(GHC.Base.map Data.Text.pack ["name"])
((GHC.Base.map Database.Persist.Class.PersistField.toPersistValue)
GHC.Base.$
(Database.Persist.Class.PersistEntity.toPersistFields ent_a9ov))))
Database.Persist.Class.PersistField.fromPersistValue
= ((\ x_a9ow
-> let columns_a9ox = Data.HashMap.Strict.fromList x_a9ow
in
(Database.Persist.Class.PersistEntity.fromPersistValues
GHC.Base.$
((GHC.Base.map
(\ name_a9oy
-> case
Data.HashMap.Base.lookup (Data.Text.pack name_a9oy) columns_a9ox
of {
GHC.Base.Just v_a9oz -> v_a9oz
GHC.Base.Nothing -> Database.Persist.Types.Base.PersistNull }))
GHC.Base.$ ["name"])))
Control.Monad.<=<
Database.Persist.Class.PersistField.getPersistMap)
instance Database.Persist.Sql.Class.PersistFieldSql Manufacturer where
Database.Persist.Sql.Class.sqlType _
= Database.Persist.Types.Base.SqlString
data Manufacturer
= Manufacturer {manufacturerName :: !Text}
deriving (Show, Read, Typeable)
type ManufacturerId =
Database.Persist.Class.PersistEntity.Key Manufacturer
instance Database.Persist.Class.PersistEntity.PersistEntity Manufacturer where
type Database.Persist.Class.PersistEntity.PersistEntityBackend Manufacturer = Database.Persist.Sql.Types.SqlBackend
data Database.Persist.Class.PersistEntity.Unique Manufacturer
= UniqueManufacturer Text
newtype Database.Persist.Class.PersistEntity.Key Manufacturer
= ManufacturerKey {unManufacturerKey :: Database.Persist.Class.PersistStore.BackendKey Database.Persist.Sql.Types.SqlBackend}
deriving (GHC.Show.Show,
GHC.Read.Read,
GHC.Classes.Eq,
GHC.Classes.Ord,
Web.PathPieces.PathPiece,
Web.HttpApiData.Internal.ToHttpApiData,
Web.HttpApiData.Internal.FromHttpApiData,
Database.Persist.Class.PersistField.PersistField,
Database.Persist.Sql.Class.PersistFieldSql,
Data.Aeson.Types.Class.ToJSON,
Data.Aeson.Types.Class.FromJSON)
data Database.Persist.Class.PersistEntity.EntityField Manufacturer typ
= typ ~ Database.Persist.Class.PersistEntity.Key Manufacturer =>
ManufacturerId |
typ ~ Text => ManufacturerName
Database.Persist.Class.PersistEntity.keyToValues
= ((GHC.Types.: [])
GHC.Base..
(Database.Persist.Class.PersistField.toPersistValue
GHC.Base.. unManufacturerKey))
Database.Persist.Class.PersistEntity.keyFromValues
= ((GHC.Base.fmap ManufacturerKey)
GHC.Base..
(Database.Persist.Class.PersistField.fromPersistValue
GHC.Base.. Database.Persist.TH.headNote))
Database.Persist.Class.PersistEntity.entityDef _
= Database.Persist.Types.Base.EntityDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Manufacturer"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "manufacturer"))
(Database.Persist.Types.Base.FieldDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Id"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "id"))
(Database.Persist.Types.Base.FTTypeCon
GHC.Base.Nothing (Database.Persist.TH.packPTH "ManufacturerId"))
Database.Persist.Types.Base.SqlInt64
[]
GHC.Types.True
(Database.Persist.Types.Base.ForeignRef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Manufacturer"))
(Database.Persist.Types.Base.FTTypeCon
(GHC.Base.Just (Database.Persist.TH.packPTH "Data.Int"))
(Database.Persist.TH.packPTH "Int64"))))
[Database.Persist.TH.packPTH "json"]
[Database.Persist.Types.Base.FieldDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "name"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "name"))
(Database.Persist.Types.Base.FTTypeCon
GHC.Base.Nothing (Database.Persist.TH.packPTH "Text"))
Database.Persist.Types.Base.SqlString
[]
GHC.Types.True
Database.Persist.Types.Base.NoReference]
[Database.Persist.Types.Base.UniqueDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "UniqueManufacturer"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "unique_manufacturer"))
[(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "name"),
Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "name"))]
[]]
[]
[Database.Persist.TH.packPTH "Show",
Database.Persist.TH.packPTH "Read",
Database.Persist.TH.packPTH "Typeable"]
(Data.Map.Base.fromList [])
GHC.Types.False
Database.Persist.Class.PersistEntity.toPersistFields
(Manufacturer x_a9oA)
= [Database.Persist.Class.PersistField.SomePersistField x_a9oA]
Database.Persist.Class.PersistEntity.fromPersistValues [x1_a9oC]
= Manufacturer
Data.Functor.<$>
((Database.Persist.TH.mapLeft
(Database.Persist.TH.fieldError
(Database.Persist.TH.packPTH "name")))
GHC.Base.. Database.Persist.Class.PersistField.fromPersistValue)
x1_a9oC
Database.Persist.Class.PersistEntity.fromPersistValues x_a9oB
= (Data.Either.Left
GHC.Base.$
(GHC.Base.mappend
(Database.Persist.TH.packPTH
"Manufacturer: fromPersistValues failed on: ")
(Data.Text.pack GHC.Base.$ (GHC.Show.show x_a9oB))))
Database.Persist.Class.PersistEntity.persistUniqueToFieldNames
(UniqueManufacturer {})
= [(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "name"),
Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "name"))]
Database.Persist.Class.PersistEntity.persistUniqueToValues
(UniqueManufacturer x_a9oD)
= [Database.Persist.Class.PersistField.toPersistValue x_a9oD]
Database.Persist.Class.PersistEntity.persistUniqueKeys
(Manufacturer _name_a9oE)
= [UniqueManufacturer _name_a9oE]
Database.Persist.Class.PersistEntity.persistFieldDef ManufacturerId
= Database.Persist.Types.Base.FieldDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Id"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "id"))
(Database.Persist.Types.Base.FTTypeCon
GHC.Base.Nothing (Database.Persist.TH.packPTH "ManufacturerId"))
Database.Persist.Types.Base.SqlInt64
[]
GHC.Types.True
(Database.Persist.Types.Base.ForeignRef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Manufacturer"))
(Database.Persist.Types.Base.FTTypeCon
(GHC.Base.Just (Database.Persist.TH.packPTH "Data.Int"))
(Database.Persist.TH.packPTH "Int64")))
Database.Persist.Class.PersistEntity.persistFieldDef
ManufacturerName
= Database.Persist.Types.Base.FieldDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "name"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "name"))
(Database.Persist.Types.Base.FTTypeCon
GHC.Base.Nothing (Database.Persist.TH.packPTH "Text"))
Database.Persist.Types.Base.SqlString
[]
GHC.Types.True
Database.Persist.Types.Base.NoReference
Database.Persist.Class.PersistEntity.persistIdField
= ManufacturerId
Database.Persist.Class.PersistEntity.fieldLens ManufacturerId
= Database.Persist.TH.lensPTH
Database.Persist.Class.PersistEntity.entityKey
(\ (Database.Persist.Class.PersistEntity.Entity _ value_a9oF)
key_a9oG
-> Database.Persist.Class.PersistEntity.Entity key_a9oG value_a9oF)
Database.Persist.Class.PersistEntity.fieldLens ManufacturerName
= Database.Persist.TH.lensPTH
(manufacturerName
GHC.Base.. Database.Persist.Class.PersistEntity.entityVal)
(\ (Database.Persist.Class.PersistEntity.Entity key_a9oH
value_a9oI)
x_a9oJ
-> Database.Persist.Class.PersistEntity.Entity
key_a9oH (value_a9oI {manufacturerName = x_a9oJ}))
instance Database.Persist.Class.PersistStore.ToBackendKey Database.Persist.Sql.Types.SqlBackend Manufacturer where
Database.Persist.Class.PersistStore.toBackendKey
= unManufacturerKey
Database.Persist.Class.PersistStore.fromBackendKey
= ManufacturerKey
instance Data.Aeson.Types.Class.ToJSON Manufacturer where
Data.Aeson.Types.Class.toJSON (Manufacturer name_a9oL)
= Data.Aeson.Types.Internal.object
[((Data.Text.pack "name") Data.Aeson.Types.Instances..= name_a9oL)]
instance Data.Aeson.Types.Class.FromJSON Manufacturer where
Data.Aeson.Types.Class.parseJSON
(Data.Aeson.Types.Internal.Object obj_a9oK)
= ((GHC.Base.pure Manufacturer)
GHC.Base.<*>
(obj_a9oK Data.Aeson.Types.Instances..: (Data.Text.pack "name")))
Data.Aeson.Types.Class.parseJSON _ = GHC.Base.mzero
instance Data.Aeson.Types.Class.ToJSON (Database.Persist.Class.PersistEntity.Entity Manufacturer) where
Data.Aeson.Types.Class.toJSON
= Database.Persist.Class.PersistEntity.entityIdToJSON
instance Data.Aeson.Types.Class.FromJSON (Database.Persist.Class.PersistEntity.Entity Manufacturer) where
Data.Aeson.Types.Class.parseJSON
= Database.Persist.Class.PersistEntity.entityIdFromJSON
migrateAll :: Database.Persist.Sql.Types.Migration
migrateAll
= do { let defs_a9oM
= [Database.Persist.Types.Base.EntityDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Manufacturer"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "manufacturer"))
(Database.Persist.Types.Base.FieldDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Id"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "id"))
(Database.Persist.Types.Base.FTTypeCon
GHC.Base.Nothing (Database.Persist.TH.packPTH "ManufacturerId"))
Database.Persist.Types.Base.SqlInt64
[]
GHC.Types.True
(Database.Persist.Types.Base.ForeignRef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Manufacturer"))
(Database.Persist.Types.Base.FTTypeCon
(GHC.Base.Just (Database.Persist.TH.packPTH "Data.Int"))
(Database.Persist.TH.packPTH "Int64"))))
[Database.Persist.TH.packPTH "json"]
[Database.Persist.Types.Base.FieldDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "name"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "name"))
(Database.Persist.Types.Base.FTTypeCon
GHC.Base.Nothing (Database.Persist.TH.packPTH "Text"))
Database.Persist.Types.Base.SqlString
[]
GHC.Types.True
Database.Persist.Types.Base.NoReference]
[Database.Persist.Types.Base.UniqueDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "UniqueManufacturer"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "unique_manufacturer"))
[(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "name"),
Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "name"))]
[]]
[]
[Database.Persist.TH.packPTH "Show",
Database.Persist.TH.packPTH "Read",
Database.Persist.TH.packPTH "Typeable"]
(Data.Map.Base.fromList [])
GHC.Types.False];
Database.Persist.Sql.Migration.migrate
defs_a9oM
(Database.Persist.Types.Base.EntityDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Manufacturer"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "manufacturer"))
(Database.Persist.Types.Base.FieldDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Id"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "id"))
(Database.Persist.Types.Base.FTTypeCon
GHC.Base.Nothing (Database.Persist.TH.packPTH "ManufacturerId"))
Database.Persist.Types.Base.SqlInt64
[]
GHC.Types.True
(Database.Persist.Types.Base.ForeignRef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "Manufacturer"))
(Database.Persist.Types.Base.FTTypeCon
(GHC.Base.Just (Database.Persist.TH.packPTH "Data.Int"))
(Database.Persist.TH.packPTH "Int64"))))
[Database.Persist.TH.packPTH "json"]
[Database.Persist.Types.Base.FieldDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "name"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "name"))
(Database.Persist.Types.Base.FTTypeCon
GHC.Base.Nothing (Database.Persist.TH.packPTH "Text"))
Database.Persist.Types.Base.SqlString
[]
GHC.Types.True
Database.Persist.Types.Base.NoReference]
[Database.Persist.Types.Base.UniqueDef
(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "UniqueManufacturer"))
(Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "unique_manufacturer"))
[(Database.Persist.Types.Base.HaskellName
(Database.Persist.TH.packPTH "name"),
Database.Persist.Types.Base.DBName
(Database.Persist.TH.packPTH "name"))]
[]]
[]
[Database.Persist.TH.packPTH "Show",
Database.Persist.TH.packPTH "Read",
Database.Persist.TH.packPTH "Typeable"]
(Data.Map.Base.fromList [])
GHC.Types.False) }
错误消息在 ->
处报告了解析错误在线以 GHC.Base.Nothing ->
开头
(\ name_a9oy
-> case
Data.HashMap.Base.lookup (Data.Text.pack name_a9oy) columns_a9ox
of {
GHC.Base.Just v_a9oz -> v_a9oz
GHC.Base.Nothing -> Database.Persist.Types.Base.PersistNull }))
最佳答案
编辑:您不能直接重用在 ghc 构建中生成的代码,但您可以简单地在 ghcjs 代码中使用包含持久数据库模型的模块。这将使用 GHCJS 生成和构建数据库内容,然后它可用于您的 GHCJS 代码。
关于postgresql - GHCJS 是否可以重用 Template Haskell 生成的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37763452/
我通过堆栈安装了 GHC(以便 stack ghc -- --version 显示 GHC-7.10.3 ) $ stack install ghcjs Run from outside a proj
我正在使用 nix 和 reflex 平台将 haskell 编译为带有 GHCJS 8.0.1 的 javascript。我编写了一些依赖于 text 库中的内部模块的函数:Data.Text.In
我对 Haskell 和 ghcjs 还很陌生。我从第一个“Hello, world!”开始。程序学习。 这是我的 Haskell 程序,从 GHCJS wiki 复制而来: module Main
如果有人使用 setInterval通过 Javascript,还是使用基于线程的更惯用的解决方案? 最佳答案 使用 setInterval构成 some challenges Alexander、E
如果是这样,那么我可以让人们通过更改其(Haskell)配置来玩弄我的项目:在浏览器中重新编译它,然后在浏览器中重新运行它。我不在乎速度。我只想能够在浏览器中演示一个难以设置的桌面项目。因此,可能的新
我正在尝试了解如何使用 GHCJS-DOM 创建 GUI。我一直在看 hello world 示例 https://github.com/ghcjs/ghcjs-dom-hello ,这是微不足道的。
我正在测试我自己的 ghcjs 补丁,我想知道如何将其打包以与堆栈的字段一起使用,这似乎需要类似的内容: setup-info: ghcjs: source: ghcjs-0.
HTML5 引入了标准文件 API。 GHCJS 是否允许访问该内容?我可以在 System.IO 中使用标准 Haskell IO 工具吗? 最佳答案 我认为不可能使用 HTML5 文件 API 来
我如何在 GHCJS 中进行多行国外导入?我有一个跨越多行的 javascript block : foreign import javascript unsafe "{ var x = 41;\
我正在开发一个 Haskell 应用程序,该应用程序在使用 GHCJS 编译的浏览器中运行,该应用程序通过 websockets 与同样用 Haskell 编写的服务器通信。两个程序共享相同的 Has
堆栈文档提供了使用 ghcjs 进行编译的示例配置 https://docs.haskellstack.org/en/stable/ghcjs/ 。但最新的例子是 lts-7.19。我想配置堆栈以使用
我尝试使用 cabal install 安装 reflex 和 reflex-dom 我收到以下错误消息: $ cabal install reflex-dom ... cabal: The foll
使用 Haskell Stack 初始化 GHCJS 项目需要做什么? 遵循stack documentation我正在尝试初始化 GHCJS 项目,以便可以将 Haskell 代码编译为 JavaS
我想知道目前是否可以用 Haskell 编写游戏 Helm或者通过 GHCJS 在浏览器上运行的任何其他引擎? 最佳答案 这是Pong在榆树。 并不是一个完整的游戏,但是 一个turtle swimm
此时GHCJS编译失败postgresql-simple包(参见 [ 1 ])。我想用 persistent包生成数据库模型。我想知道是否可以使用 GHC 本身编译模型并在 GHCJS 源代码中重用由
我正在尝试移植 haskell 库 minisat使用 ghcjs 到 JavaScript,以便集成到更大的 haskell-ghcjs 项目中。 minisat 包含几个从 c 库导入的 ffi。
我正在尝试使用 node.js 运行一个使用 GHCJS 构建的程序。但是,我收到以下错误: SyntaxError: Too many variables declared (only 131071
我认为埋头于所列语言的源代码对我来说太过分了。但是有没有人能够简单地解释一下事情是如何发生的? 我的意思是,最终不可变数据仍将是 javascript 的数据。或者编译后的代码是否包含非标准数据结构,
如何在 GHCJS 中导入如下 Javascript 函数? xs.subscribe(function(x) { console.log(x) }) 我尝试了以下各种组合但没有成功: data Ob
我正在尝试在 Mac OSX 上安装 ghcjs-dom 包。由于存在很多依赖关系,因此一直很坎坷。 Webkitgtk3 是我目前的克星 cabal install ghcjs-dom Resolv
我是一名优秀的程序员,十分优秀!