Current behavior Prelude> show _ <interactive>:7:6: Found hole ‘_’ with type: a0 Where: ‘a0’ is an ambiguous type variable Relevant bindings include it :: String (bound at <interactive>:7:1) In the first argument of ‘show’, namely ‘_’ In the expression: show _ In an equation for ‘it’: it = show _ Desired behavior It would be nice if GHC would also tell
目前的行为 Prelude> show _ <interactive>:7:6: Found hole ‘_’ with type: a0 Where: ‘a0’ is an ambiguous type variable Relevant bindings include it :: String (bound at <interactive>:7:1) In the first argument of ‘show’, namely ‘_’ In the expression: show _ In an equation for ‘it’: it = show _ 期望的行为 如果GHC也会告诉我这个类型的孔具有Show类的类型约束,
I am new to Haskell and I am very confused by Where vs. Let . They both seem to provide a similar purpose. I have read a few comparisons between Where vs. Let but I am having trouble discerning when to use each. Could someone please provide some context or perhaps a few examples that demonstrate when to use one over the other? Where vs. Let A where clause can only be defined at the level o
我是Haskell的新手,我很困惑Where vs. Let 。 他们似乎都提供了类似的目的。 我已经阅读了Where vs. Let之间的一些比较,但我无法辨别何时使用它们。 是否有人可以提供一些背景知识,或者可以举几个例子来说明何时使用这些背景? 在哪里与让 where子句只能在函数定义的级别定义。 通常,这与let定义的范围相同。 唯一的区别是警卫正在使用。 where子句的范围覆盖所有警卫。 相比之下, let表达式的范围只是当前的函
I'm working on a project right now where I'm dealing with the Prim typeclass and I need to ensure that a particular function I've written is specialized. That is, I need to make sure that when I call it, I get a specialized version of the function in which the Prim dictionaries get inlined into the specialized definition instead of being passed at runtime. Fortunately, this is a pr
我现在正在处理一个项目,我正在处理Prim typeclass,并且需要确保我编写的特定函数是专用的。 也就是说,我需要确保当我调用它时,我会得到一个专用版本的函数,其中Prim字典被内联到特定的定义中,而不是在运行时传递。 幸运的是,这在GHC中是一个很好理解的东西。 你可以写: {-# SPECIALIZE foo :: ByteArray Int -> Int #-} foo :: Prim a => ByteArray a -> Int foo = ... 而在我的代码中,这种方法工作正
I'm trying to ensure that GHC specializes a recursive function to so that everything gets unboxed. The full example code (as well as a dump of the GHC core) is available in this gist. The function in question looks like this: import Data.Bits import qualified Data.Vector.Unboxed as UV lookupSorted :: Ord a => (Int -> a) -> Int -> a -> Ma
我正在努力确保GHC专门设计一个递归函数,以便所有东西都可以被拆箱。 完整的示例代码(以及GHC内核的转储)在本要点中可用。 有问题的功能如下所示: import Data.Bits import qualified Data.Vector.Unboxed as UV lookupSorted :: Ord a => (Int -> a) -> Int -> a -> Maybe Int lookupSorted lookupIx len needle = let !r = go 0 (len - 1)
fgl is a Haskell library for graph manipulation. This library comes with an implementation of its base classes - Data.Graph.Inductive.PatriciaTree - that is supposedly highly tuned for performance. Part of that performance tuning involves ghc RULES pragmas to replace certain generic functions with specialized versions that are much faster. However, my evidence is that these RULES don't se
fgl是一个用于图形操作的Haskell库。 这个库附带一个基本类的实现 - Data.Graph.Inductive.PatriciaTree - 据说对性能高度优化。 性能调优的一部分涉及ghc RULES编译指示,用特定版本取代某些通用函数,该版本速度更快。 但是,我的证据是,这些规则似乎根本不起作用,我不明白为什么不行。 对于那些试图复制我所看到的内容的人,我已经在https://github.com/fizbin/GraphOptiTest上提供了我的测试项目,并使用ghc版本7.10.
I want to be able to call LLVM code from Haskell without the overhead of a full function call. For example: -- Main.hs -- {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE GHCForeignImportPrim #-} {-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE UnliftedFFITypes #-} {-# LANGUAGE BangPatterns #-} import GHC.Exts(Word(W#)) import GHC.Prim(Word#) foreign import ccall
我希望能够从Haskell调用LLVM代码,而不需要全部函数调用的开销。 例如: -- Main.hs -- {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE GHCForeignImportPrim #-} {-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE UnliftedFFITypes #-} {-# LANGUAGE BangPatterns #-} import GHC.Exts(Word(W#)) import GHC.Prim(Word#) foreign import ccall llvminc :: Word# -> Word# main = do
I have a body of code that uses a monad to abstract whether the actual implementation runs inside ST or IO. Removing the extra layer of abstraction and just substituting concrete types gives a huge speedup (~4.5x) due to the inlining and missing typeclass function call overhead. I was thinking of getting some of that performance by using a specialize pragma, but I'm getting a rather meaning
我有一个使用monad来抽象实际实现是在ST还是IO内运行的代码体。 由于内联和缺少类型类函数调用开销,移除额外的抽象层并仅替换具体类型会带来巨大的加速(〜4.5x)。 我正在考虑通过使用专门的编译指示来获得一些性能,但我从编译器中获得了一个毫无意义的警告。 我不能做一个简单的复制案例,因为这个简单的例子似乎有效,我不知道是什么导致了我的实际程序中的差异。 基本上,我的程序执行此操作: {-# LANGUAGE Flexible
Does anyone know why this code: module Language.P4.UtilTest where import Language.P4.Util (mkShow) data Dummy = Bogus Char | Nonsense Int $(mkShow ''Dummy) is producing this error: Davids-Air-2:P4 dbanas$ stack ghc -- UtilTest.hs -ddump-splices [1 of 1] Compiling Language.P4.UtilTest ( UtilTest.hs, UtilTest.o ) UtilTest.hs:24:3-16: Splicing declarations mkShow ''Dummy ==
有谁知道为什么这个代码: module Language.P4.UtilTest where import Language.P4.Util (mkShow) data Dummy = Bogus Char | Nonsense Int $(mkShow ''Dummy) 正在产生这个错误: Davids-Air-2:P4 dbanas$ stack ghc -- UtilTest.hs -ddump-splices [1 of 1] Compiling Language.P4.UtilTest ( UtilTest.hs, UtilTest.o ) UtilTest.hs:24:3-16: Splicing declarations mkShow ''Dummy ======>
I have the following: import Control.Applicative import Control.Monad import Language.Haskell.TH mkExp :: [Name] -> ExpQ mkExp (name:[]) = [| ZipList $(varE name) |] mkExp (name:names) = [| ZipList $(varE name) <*> $(mkExp names) |] zipN :: Int -> ExpQ zipN n = do names <- mapM newName $ replicate n "x" fn <- newName "f" let vps = map varP (fn:names) lamE vps $ [| $(
我有以下几点: import Control.Applicative import Control.Monad import Language.Haskell.TH mkExp :: [Name] -> ExpQ mkExp (name:[]) = [| ZipList $(varE name) |] mkExp (name:names) = [| ZipList $(varE name) <*> $(mkExp names) |] zipN :: Int -> ExpQ zipN n = do names <- mapM newName $ replicate n "x" fn <- newName "f" let vps = map varP (fn:names) lamE vps $ [| $(varE fn
I've been playing a bit with TemplateHaskell and I came across this problem, which is basically you can't do keyword name = [d| data $(name) = $(name) |] You have to do something like keyword name = return [DataD [] name [] [NormalC name []] []] where name' = mkName name instead. Apparently the reason would be related to some typechecking problem. So the question is, why
我一直在用TemplateHaskell玩一下,我遇到了这个问题,基本上是这样 你做不到 keyword name = [d| data $(name) = $(name) |] 你必须做类似的事情 keyword name = return [DataD [] name [] [NormalC name []] []] where name' = mkName name 代替。 显然这个原因可能与一些类型检查问题有关。 所以问题是,为什么模板Haskell使用复杂的AST而不是字符串。 如果一个拼接返回一个简单的字符串并且在扩展文件中会