ghc

Haskell's type inference strangeness

扶醉桌前 提交于 2019-12-10 04:35:47
问题 Look at this output from ghci: Prelude> :t Data.Map.lookup Data.Map.lookup :: Ord k => k -> Data.Map.Map k a -> Maybe a Prelude> :t flip Data.Map.lookup flip Data.Map.lookup :: Ord a => Data.Map.Map a a1 -> a -> Maybe a1 Prelude> let look = flip Data.Map.lookup Loading package array-0.3.0.2 ... linking ... done. Loading package containers-0.4.0.0 ... linking ... done. Prelude> :t look look :: Data.Map.Map () a -> () -> Maybe a Why look 's inferred type differs from type of flip Data.Map

How can I get GHC to generate instances of Data.Typeable for GADTs with Typeable in the context?

大兔子大兔子 提交于 2019-12-10 04:17:23
问题 Suppose I have the following code: {-# LANGUAGE GADTs, DeriveDataTypeable, StandaloneDeriving #-} import Data.Typeable class Eq t => OnlyEq t class (Eq t, Typeable t) => BothEqAndTypeable t data Wrapper a where Wrap :: BothEqAndTypeable a => a -> Wrapper a deriving instance Eq (Wrapper a) deriving instance Typeable1 Wrapper Then, the following instance declaration works, without a constraint on t : instance OnlyEq (Wrapper t) and does what I expect it to do. But the following instance

Haskell / GHC: {-# SPECIALIZE #-} Causes 'RULE left-hand side too complicated to desugar' Warning

点点圈 提交于 2019-12-10 04:10:17
问题 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 meaningless warning from the compiler. I can't make a simple reproduction case as the simple example seems to

Comparing speed of Haskell and C for the computation of primes

一世执手 提交于 2019-12-10 03:56:34
问题 I initially wrote this (brute force and inefficient) method of calculating primes with the intent of making sure that there was no difference in speed between using "if-then-else" versus guards in Haskell (and there is no difference!). But then I decided to write a C program to compare and I got the following (Haskell slower by just over 25%) : (Note I got the ideas of using rem instead of mod and also the O3 option in the compiler invocation from the following post : On improving Haskell's

Haskell, Hackage, GHC and productivity. What to do? [closed]

醉酒当歌 提交于 2019-12-10 03:48:58
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . For a year I've been a rookie haskeller ("rookie haskeller" forever, I think). I have coded little haskell programs (eg. a very simple

How to construct generic Functor instances using GHC.Generics (or other similar frameworks)?

二次信任 提交于 2019-12-10 02:50:05
问题 I'm trying to learn GHC Generics. After reviewing several examples, I wanted to try to create a generic Functor instances (disregarding that GHC can derive them automatically for me). However, I realized I have no idea how to work with a parametrized data types with Generics, all the examples I've seen were of kind * . Is this possible, and if yes, how? (I'm also interested in other similar frameworks, such as SYB.) 回答1: The best place to look for lots of example functions using GHC Generics

Interfacing Haskell and C++

喜夏-厌秋 提交于 2019-12-10 01:50:18
问题 I'd like to call some Haskell functions in a c++ program. In order to do so, i have applied these instructions and adapted them to my code and system. What I have for the moment is the following: Main.cpp Shared header and cpp files makefile cpp/ some cpp and header files haskell/ hello.hs The make file is the following: CPP_SOURCES = main.cpp textures.cpp cpp/game.cpp \ cpp/piece.cpp cpp/factories.cpp cpp/utils.cpp HASKELL_SOURCES = haskell/hello.hs all: main; ./main main: $(CPP_SOURCES)

When is UndecidableInstances safe? Some general questions regarding the GHC extension

[亡魂溺海] 提交于 2019-12-10 01:16:19
问题 I know of the documentation for -XUndecidableInstances, but I thought I'd ask for an elaboration. Suppose I have two multi-parameter typeclasses (allowed with -XMultiParamTypeClasses) class Foo a b class Goo a b Now, suppose I have a parameterized data type data Bar a b which I want to make an instance of Foo when one of its parameters is part of an instance of Goo . I'm not sure the previous sentence uses exact terminology, so here's what I want to write: instance (Goo c d) => Foo d (Bar a d

Can GHC unpack enumerations on strict data fields?

最后都变了- 提交于 2019-12-10 01:14:30
问题 In a comment on the previous question, I claimed: I have another benchmark to indicate ghc-7.4.1+llvm does unpacking of enumerations on strict data fields. In fact, after some experimentation, I believe that, in at least some simplistic cases, using an enumeration is at least as fast as, and actually might be more memory efficient (hence faster in a more realistic application) than using a newtype of Word8 (or Int), even when used in a strict field of a datatype. As I said in the previous

Why can't GHC derive instances for Monoid?

我与影子孤独终老i 提交于 2019-12-10 01:10:15
问题 GHC has a few language flags, such as DeriveFunctor , DeriveDataTypeable etc., which enable compiler generation of derived instances for type classes other than those allowed in Haskell 98. This especially makes sense for something like Functor , where the laws of that class dictate an obvious, "natural" derived instance. So why not for Monoid ? It seems like for any data type with a single data constructor: data T = MkT a b c ... one could mechanically produce a Monoid instance (excuse the