小编fun*_*ial的帖子

Haskell cabal-install错误

我遇到了很多问题cabal-install:
1:每次我这样做cabal update,它都会告诉我这样做cabal install cabal-install,所以我这样做,然后当我cabal update再次这样做时,它会说同样的事情.

2:当我尝试ghc-mod从hackage 安装时,它给了我这个错误:

[username@arch ~]$ cabal install ghc-mod
In order, the following will be installed:
haskell-src-exts-1.14.0 (reinstall) changes: pretty-1.1.1.1 -> 1.1.1.0
hlint-1.8.55 (reinstall)
ghc-mod-3.1.4
setup: The program happy version >=1.17 is required but it could not be found.
ghc-mod-3.1.4 depends on haskell-src-exts-1.14.0 which failed to install.
haskell-src-exts-1.14.0 failed during the configure step.
hlint-1.8.55 depends on haskell-src-exts-1.14.0 which failed to install.
Run Code Online (Sandbox Code Playgroud)

所以问题是The program happy version …

haskell package cabal cabal-install

21
推荐指数
2
解决办法
5553
查看次数

将复杂的参数传递给 GraphQL 突变

我一直在使用 graphql-js 在 Node 服务器中使用 GraphQL,并且 GraphQL 已被证明是一个非常有价值的抽象,但我遇到了一个问题。

我经常发现自己需要将大型结构化对象作为参数传递给 GraphQL 突变,使用GraphQLInputObjectType. 这很好,但 GraphQL 不支持使用 JSON 表示法 :(。所以我最终只发送一个包含 JSON 的字符串,供服务器处理。

const objectStr = JSON.stringify(object).replace(new RegExp("\"", "g"), "'")

graphQLClient(`{
    user: updateUser(someDataObject: "${objectStr}") {...}
}`)
Run Code Online (Sandbox Code Playgroud)

但是现在我根本没有从 GraphQL 中受益!

我有一种感觉,我在这里做错了。GraphQL 将注册表单数据发送到突变的方式是什么?

javascript node.js graphql

6
推荐指数
1
解决办法
3545
查看次数

Haskell Netwire - 输入错误

我刚刚开始使用netwire,我遇到了很多基础问题.

以下代码对我来说很好:

main :: IO ()
main = testWire clockSession_ (for 3 . yeah)

yeah :: Monad m => Wire s () m a String
yeah = pure "yes"
Run Code Online (Sandbox Code Playgroud)

但这不是:

main :: IO ()
main = testWire clockSession_ forYeah

forYeah :: (Show b, Show e) => Wire s e Identity a b
forYeah = for 3 . yeah
Run Code Online (Sandbox Code Playgroud)

失败并出错:

Could not deduce (b ~ [Char])
from the context (Show b, Show e)
bound by the type signature for
forYeah :: …
Run Code Online (Sandbox Code Playgroud)

haskell functional-programming frp netwire

5
推荐指数
1
解决办法
287
查看次数

Haskell IORef数组用法

我正在开发一个程序,它使用大量IORef的数据类型列表.哪种内存/处理器效率更高的方法:

[IORef Foo]
Run Code Online (Sandbox Code Playgroud)

要么

IORef [Foo]
Run Code Online (Sandbox Code Playgroud)

忽略我使用列表而不是向量或数组的事实.

monads haskell functional-programming data-structures ioref

5
推荐指数
1
解决办法
364
查看次数

OpenGL旋转过于敏感

我最近gl_*Matrix自己使用了已弃用的处理矩阵.一切似乎都很好,除了旋转大约是应该的80倍.我可以切换到使用opengl的矩阵而不更改任何其他代码,并且旋转很好.完整的源代码在Github上.最相关的功能在这里:

calculateMatricesFromPlayer :: GameObject a -> WorldMatrices
calculateMatricesFromPlayer p@(Player{}) =
    let Vec3 px py pz = playerPosition p
        Vec3 rx ry _ = playerRotation p

        -- Create projection matrix
        projMat = gperspectiveMatrix 45 (800/600) 0.1 100

        -- Create view matrix
        rotatedMatX = grotationMatrix rx [-1, 0, 0]
        rotatedMatXY = rotatedMatX * grotationMatrix ry [0, -1, 0]
        translatedMat = gtranslationMatrix [-px, -py, -pz]
        viewMat = rotatedMatXY * translatedMat

        -- Model matrix is identity by default
        modelMat = …
Run Code Online (Sandbox Code Playgroud)

opengl haskell matrix linear-algebra

2
推荐指数
1
解决办法
144
查看次数

Haskell IO和带递归的数组

我在编写类型
Int -> IO [Int]或函数时遇到问题Int -> [IO Int]

我有以下代码不起作用:

createEIList :: Int -> IO [Int]
createEIList len = do
    cur <- createEI
    (return cur):(createEIList (len-1))
Run Code Online (Sandbox Code Playgroud)

createEI的位置 createEI :: IO Int

做这样的事情的最佳方法是什么?

arrays io recursion haskell functional-programming

1
推荐指数
1
解决办法
181
查看次数

Haskell最有效的可变数据结构

我正在Haskell中编写一个目前有类似数据类型的游戏程序

data World = World {
    worldPlayer :: !(IORef GameObject),
    worldEntities :: ![IORef GameObject],
    ...
}
Run Code Online (Sandbox Code Playgroud)

每次更新时,以下更新都会写入播放器IORef:

updatePlayer :: GameObject -> [IORef GameObject] -> IO GameObject
Run Code Online (Sandbox Code Playgroud)

在此函数中,它检查每个对象的碰撞,然后移动播放器.但我希望updatePlayer函数是纯粹的,所以我需要使用不同的数据结构.

最明显的想法是[IORef GameObject]从世界中获取并IO [GameObject]通过调用readIORef每个索引将其转换为a .但这样效率很低.

我发现这样做的另一种可能方法是使用Data.Vector.MVectorand Data.Vector.Generic.unsafeUnfreezeunsafeFreeze,它们具有O(1)性能worldEntities :: !(MVector (PrimState IO) GameObject).问题是,unsafeUnfreezeunsafeFreeze对某些数据类型唯一的工作.

我也发现IOArray,所以我可以使用IOArray Int GameObject,但我找不到将IOArrays转换为不可变结构的方法.

最后,我可以做IORef [GameObject]或者IORef (Vector GameObject),但我不确定这会有多高效.

最有效的方法是什么?

arrays performance haskell functional-programming data-structures

1
推荐指数
1
解决办法
1071
查看次数