ghc

How can I get `ghci` to use my `show` function?

纵饮孤独 提交于 2019-12-05 03:51:17
Let's say you want to use your own show function (for example, let show = take 1000 . Prelude.show ). How can you allow ghci to use that for printing instead of the built in show ? Lee You can define your own interactive print function e.g: module BetterPrint betterPrint a = putStrLn (take 1000 $ show a) then start ghci as ghci -interactive-print=BetterPrint.betterPrint 来源: https://stackoverflow.com/questions/35613612/how-can-i-get-ghci-to-use-my-show-function

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

岁酱吖の 提交于 2019-12-05 03:43:26
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.) The best place to look for lots of example functions using GHC Generics is the generic-deriving package . There's a generic definition of the Functor class in there. Copying

RankNTypes: What is causing this error?

夙愿已清 提交于 2019-12-05 03:42:11
I've just been exploring Rank2Types and RankNTypes to try to get familiar with them. But I can't work out why the following does not work. g :: (forall a. forall b. a -> b) -> x -> y -> (u,v) g p x y = (p x, p y) This definition is accepted by the compiler, but it fails when I try to use it: ghci> g id 1 2 <interactive>:35:3: Couldn't match type `a' with `b' `a' is a rigid type variable bound by a type expected by the context: a -> b at <interactive>:35:1 `b' is a rigid type variable bound by a type expected by the context: a -> b at <interactive>:35:1 Expected type: a -> b Actual type: a -> a

A change in my library made it much slower. Profiling isn't helping me. What might be the reason for the slow-down?

喜你入骨 提交于 2019-12-05 02:44:51
My Problem, Briefly I made a change to my library, now it's much slower but I can't figure out where it spends all that additional time. Profiling reports are not helping. Please help me figure out what the reason might be. Some Context I made a Redis client-library called Hedis and have a benchmark program for it. Now, I made some internal changes to the library, to clean up the architecture. This caused performance (in Redis-requests per second, as measured by said benchmark) to drop by a factor of about 2.5. The benchmark opens 50 network connections to a Redis server on localhost. The

Control.Parallel compile issue in Haskell

删除回忆录丶 提交于 2019-12-05 01:42:26
The compiler is complaining each time on different example applications of parallel Haskell; with this message: Could not find module `Control.Parallel.Strategies' The ghc compiler command: ghc -threaded -i/sudo/dir/par-modules/3 -cpp -DEVAL_STRATEGIES -eventlog --make parFib.hs Same with simpler ghc -O2 --make -threaded parFib.hs What detail am I overlooking? Am I missing some PATH variable. Imports can look like this: module Main where import System # if defined(EVAL_STRATEGIES) import Control.Parallel import Control.Parallel.Strategies #endif Cheers You must install the parallel package

How do I install dependencies when cross compiling haskell code?

こ雲淡風輕ζ 提交于 2019-12-05 00:51:36
I've successfully created a ghc cross compiler, that allows me to compile haskell code for armv6h (raspberry pi in my case) from my x64 linux machine. I've successfully run a hello world program on the raspberry. No I want to build my real app, which has a lot of dependencies on other haskell modules. When I compile for x64 I simply do cabal install dependenciy1 depenency2 ... I know I could make my own programm a cabal-project an automate this step. But that's not the point here. When I try to use the cross-compiler arm-unknown-linux-gnueabi-ghc --make myapp.hs It tells me about modules it

What is the difference between `ioToST` and `unsafeIOToST` from GHC.IO

半腔热情 提交于 2019-12-05 00:44:31
What can the differences and intended uses be for ioToST and unsafeSTToIO defined in GHC.IO ? -- --------------------------------------------------------------------------- -- Coercions between IO and ST -- | A monad transformer embedding strict state transformers in the 'IO' -- monad. The 'RealWorld' parameter indicates that the internal state -- used by the 'ST' computation is a special one supplied by the 'IO' -- monad, and thus distinct from those used by invocations of 'runST'. stToIO :: ST RealWorld a -> IO a stToIO (ST m) = IO m ioToST :: IO a -> ST RealWorld a ioToST (IO m) = (ST m) --

Profiling a partially evaluated program

这一生的挚爱 提交于 2019-12-05 00:42:41
For the purposes of profiling a partially evaluated program, I'm interested in knowing the best way to terminate a GHC program. This is useful for profiling programs that take a long time to run, possibly as long as forever. With GHC 7.4.2, I was able to profile a non-terminating program by enabling profiling (-prof -auto-all) and running my program with +RTS -p . This generated incremental profiling data. The program could be killed with ^c , and the .prof file would contain data. In GHC 7.6 and later, it appears that if the program can be terminated with a single ^c, then profiling

Haskell / GHC — is there any infix tag / pragma for “warn incomplete patterns”

故事扮演 提交于 2019-12-05 00:11:04
I'm looking for a pragma that will warn on a particular incomplete pattern. It would make the compiler fail with the following (hypothetical) code: {-# FAILIF incomplete-patterns #-} f :: Int -> Int f 0 = 0 I am trying to write a "compiler" using Arrows, and knowing pattern matching is complete would help isolate bugs. Thanks! You can require warnings, including incomplete patterns, with -Wall : {-# OPTIONS_GHC -Wall #-} module A where f :: Int -> Int f 0 = 0 Yielding: A.hs:6:1: Warning: Pattern match(es) are non-exhaustive In an equation for `f': Patterns not matched: GHC.Types.I# #x with #x

Why can't GHC derive instances for Monoid?

妖精的绣舞 提交于 2019-12-05 00:00:41
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 pseudocode): instance (Monoid a, Monoid b, Monoid c, ...) => Monoid T where mempty = MkT mempty mempty