haskell,ghc,generic-programming,template-haskell,scrap-your-boilerplate
If you leave the recursion in your data type open you end up suffering an extra constructor everywhere, but can layer in annotations freely without changing most of your skeletal tree. data Hutton x -- non-recursive functor type = Int Int | Plus x x deriving Functor newtype Tie f...
haskell,optimization,garbage-collection,ghc
gloss is the culprit here. First, a little background on GHC's garbage collector. GHC uses (by default) a generational, copying garbage collector. This means that the heap consists of several memory areas called generations. Objects are allocated into the youngest generation. When a generation becomes full, it is scanned for...
performance,haskell,functional-programming,ghc,memoization
You memoize a function by associating it with a data structure that 'remembers' past applications. Ghc won't remember arbitrary past function applications, but it does remember as much as it has worked out of structure that it is still working on. In this case, the function pascalRow is not really...
haskell,memory,garbage-collection,ghc,compiler-optimization
Let's compare actual numbers. Your version of kolakoski uses about 70k if run without optimization: $ ghc --make Kolakoski-Unit && ./Kolakoski-Unit +RTS -s 2 288,002,359,096 bytes allocated in the heap 1,343,933,816 bytes copied during GC 67,576 bytes maximum residency (422 sample(s)) 52,128 bytes maximum slop 2 MB total memory in...
haskell,ghc,scrap-your-boilerplate,ghc-generics
It sounds like you want a Functor instance. This can be automatically derived by GHC using the DeriveFunctor extension.
performance,haskell,ghc,lazy-evaluation,evaluation
The final step of len is not O(1). It is O(n) to add together n numbers. len also uses O(n) memory while slen uses O(1) memory. The reason it uses O(n) memory is that each thunk uses up some memory. So when you have something like this: 1 + 1...
When you write fibsA :: Num a => [a], the compiler constructs what is essentially fibsA :: NumDict a -> [a] Where data NumDict a = NumDict { (+) :: a -> a -> a , (-) :: a -> a -> a , (*) :: a -> a ->...
Instances are only matched by the instance head. So, for the purpose of overlapping or not, what you wrote is no better than instance ToAVector [] a instance ToAVector v a which is clearly overlapping. To argue another way: ... as [] does not match G.Vector [] a ... this...
haskell,ghc,compiler-optimization,read-eval-print-loop,ghci
Either use ghci -fobject-code -O Test.hs or cabal repl --ghc-options="-fobject-code -O". In more detail: ghci must be invoked with the -fobject-code flag. Optimization flag(s) must be given after -fobject-code on the command line, or in an OPTIONS_GHC pragma at the top of the module. Trying ghc --interactive -O -fobject-code produces...
My understanding is that purely syntactical things like this don't matter; the rule will fire either way. What you will find to be a problem is that myFn might have been inlined by the time GHC tries to use the rule (so there will be nothing for it to fire...
GHC's RTS appears to use signals for its own purposes, which means it won't be long before a sleep gets interrupted by one of these signals. I don't think it's a bug either, the runtime does come with its own territory, so to speak. The Haskellian approach would be to...
haskell,ghc,real-world-haskell
This should work: ghc -o simple Main.hs SimpleJSON.hs Or even something like this should work: ghc -c SimpleJSON.hs ghc -c Main.hs ghc -o simple Main.o SimpleJSON.o Or as @chi points out, you can use this: ghc --make SimpleJSON.hs Main.hs ...
Was able to figure this out with the parsers in Language.Haskell.Exts, which is from haskell-src-exts. Thanks luqui!
Compiling with -Wall (or -Werror) is a good first start to finding the source of an uninitialized field. However, it might not be the source of the error. Missing record field initializions have a specific error message: Prelude> data A = A { a :: Int } deriving Show Prelude>...
haskell,operator-overloading,ghc
Actually, yes! {-# LANGUAGE FlexibleInstances #-} module Temp where instance Num a => Num (a -> a) where fromInteger n = (fromInteger n *) n + m = \x -> n x + m x -- ... Then in ghci: λ :l Temp ... λ 3 (4 :: Int) ::...
Some Linux distros offer binary RPMs of various Haskell packages. There are tools that will automatically transform a Cabal package containing source code into a binary RPM that you can just install like anything else. The problem is going to be avoiding dependency hell. Due to the way GHC is...
I did this simple test: import Data.Map as M import Data.Text as T main = do let m = M.fromList [(1, 2), (3, 4)] putStrLn $ show m and got: $ ghc imports.hs $ $ ls -l imports -rwxr-xr-x+ 1 erik staff 1583112 May 17 10:56 imports I then commented...
The parameter executable-profiling appears to have been renamed to profiling at some point. There are some other changes to the configuration parameters as well. I suspect that all I needed to do was change executable-profiling to profiling in ~/.cabal/config and re-try my cabal install. However, I didn't know a priori...
haskell,intellij-idea,ghc,ghc-mod
This question has been answered by Atsky on GitHub: This is internal problem of ghc-mod. It fails to read file dist/setup-config for some reason. Try to remove dist folder from your project and then run cabal config. ...
multithreading,performance,haskell,parallel-processing,ghc
The unexpected performance could be explained by the fact that "Crypto.Hash.SHA256" invokes unsafe FFI code. GHC does not guarantee that other Haskell threads will not be blocked during the call to this code. If the threads that par spawns are being blocked by GHC it would cause a lot of...
Situation here is similiar to C++ you have libraries used during dynamic linking stage and header used for compilation. In Fedora packages like ghc-bytestring are only libraries without headers. To install headers I had to install ghc-bytestring-devel package.
Add the CPP pragma to the top of your haskell file and add a #include foo.h line to the haskell file. The C preprocessor will expand the macros for you. See [1] for options like -Dsymbol=value which will define a macro for all the files that are compiled with that...
A Cons cell contains two things: an element and a tail. If the list is only supposed to contain one element, the tail is empty (represented by the nullary constructor Empty). So to represent a list containing 3 as its only element, you use: let x = Cons 3 Empty...
valueKind :: SomeValue a -> SomeKind is not possible. The a type parameter isn't present runtime in any shape or form, so we can't branch on it. The standard method for making use of types both at runtime and compile time is to make so-called singleton types. Singletons are indexed...
haskell,optimization,inline,ghc,cabal
GHC will do a pretty good job at high levels of optimization. If, after inspecting the Core and profiling, you determine that certain functions are not inlined when they could be, you can use INLINABLE or INLINE to increase the liklihood of inlining occuring. Recall that The major effect of...
haskell,optimization,memory-leaks,ghc
You want variants (c:s) = [c':s' | c' <- subst c, s' <- variants s] to be compiled into an outer loop and an inner loop. But GHC sees that the inner loop does not depend in any way on the outer "loop counter". Therefore, the full laziness transformation lifts...
This looks as a bug in that old Haskell library: from its source code module Graphics.UI.Gtk.ModelView.CellRenderer ( -- snip CellRendererMode, The above is not exporting the constructors. Newer versions do: module Graphics.UI.Gtk.ModelView.CellRenderer ( -- snip CellRendererMode(..), You may try to update the Haskell library to a newer version. That should...
In general GHC will allocate a new value rather than reuse the argument in that situation. In this particular case you could write something like f :: T -> T f [email protected](T x y) = t to explicitly reuse the argument. Unfortunately, in one of the cases where you'd really...
So, you haven't given me enough information in this bug per se, but I am going to attempt to use my psychic debugging powers to answer your question. You attempting to compile a GHC program which relies on packages p and q. You probably specified them using -package p and...
haskell,intellij-idea,ghc,ghc-mod
I had the same problem on Mac OS X and solved it by launching IntelliJ IDEA with open /Applications/IntelliJ\ IDEA\ 14.app shell command. If you write some scripts for Haskell in .bashrc, it doesn't affect IntelliJ IDEA launched from Desktop or Launchpad e.t.c. Using open shell command let IntelliJ IDEA...
You can use elem: > 'n' `elem` w True For future reference in case you haven't seen it before, there is actually a search engine that will look up functions based on type for Haskell. If I search for Char -> String -> Bool or String -> Char -> Bool...
Error : checking whether we are cross compiling... configure: error: in `/tmp/network-2.5.0.023068/network-2.5.0.0': configure: error: cannot run C compiled programs. If you meant to cross compile, use `--host'. See `config.log' for more details So, I run command yum groupinstall "development tools", installed c compiler tools and could compile c programs. Then,...
Don't you mean...? instance (GDefault a, GDefault b) => GDefault (a :+: b) where ... -- ^ ^ ...
haskell,garbage-collection,ghc
In the GHC garbage collector there are no hooks for hinting at the generation an object should be allocated to. However, you might be able to exploit the operational behavior in a couple of ways: depending on the data type, you may be able to exploit the pinned object region...
The issue was fixed in QuickCheck (see https://github.com/nick8325/quickcheck/issues/42).
In your quoted block: ... This requires a Unix compatibility toolchain such as MinGW+MSYS ... explicitly says MinGW+MSYS; MinGW alone is not enough. It is the MSYS tool chain which provides the unix compatible shell and most common supporting utilities, which allow this combination to process your configure script. So...
Wall-clock time includes time spent waiting for the network, disk, user input, etc. whereas CPU time only includes time actively spent computing something on (exactly) one CPU. (When computing on multiple CPUs, the time spent on each is added together.)
No, this wouldn't work. Rewrite rules are only applied if the types check. In this case the rule would only fire if you ran castVar :: Term c Void -> Term c Void, which isn't very helpful. (See https://downloads.haskell.org/~ghc/7.10.1/docs/html/users_guide/rewrite-rules.html for more info on rewrite rules) What you want is to...
Consider the following: newtype ProcessID = PID Int deriving Eq What this does is write an instances that looks like instance Eq PID where (PID x) == (PID y) = x == y In other words, when you call == on a PID, it unwraps it into an ordinary Int,...
osx,haskell,ghc,static-linking,dynamic-linking
The crucial difference is that machine #2 has /usr/local/lib in the linker path, and is using brew's linker (/usr/local/Library/ENV/4.3/ld). ghc still uses an external linker, even if it isn't using the C backend for code generation, so you can combine Haskell code with code written in other languages (crucial for...
Use getNumCapabilities. It also has a counterpart setNumCapabilities for changing the number of threads programmatically.
You can get the total heap consumption and other stats via getGCStats in module GHC.Stats, at least if you run your program with +RTS -T.
This class definition won't work, because the type of clear doesn't mention the type variable p, so it is impossible to instantiate clear with a concrete type. Adding type signatures to box or line won't help - even clear :: IO () will produce a type error. This could be...
First off, * is not a wildcard! It's also typically pronounced "star." Bleeding edge note: There is as of Feb. 2015 a proposal to simplify GHC's subkind system (in 7.12 or later). That page contains a good discussion of the GHC 7.8/7.10 story. Looking forward, GHC may drop the distinction...
haskell,types,functional-programming,ghc,typeclass
This error occurs because when you call mid (), it has the type Monoid () p0 (->) m => i -> m, and there is nothing constraining p0 to be the particular p you chose since p0 does not appear on the right hand side of the => sign in...
I greatly simplified the original question to the following, which compiles without {-# LANGUAGE PolyKinds #-} but fails to compile with PolyKinds. {-# LANGUAGE ScopedTypeVariables, KindSignatures, GADTs #-} {-# LANGUAGE PolyKinds #-} data Pair1 :: (* -> *) where Pair1 :: Pair1 (c a, c b) data D p a...
haskell,ghc,cabal,haskell-platform
Searching in the haskell-platform repository for mentions of base constraints, I found in hptool/src/Releases2015.hs a hp_7_10_2 value of type Release which seems to specify the 4.8.1.0 constraint, as well as an analogous hp2015_2_0_0 with a 4.8.0.0 constraint. That hp_7_10_2 value is used to specify the release to install in src/Main.hs,...
Probably GHC didn't recompile your program since the program hadn't changed since you last ran GHC. This seems likely since -pgmlo -pgmlc means "use -pgmlc as the LLVM optimizer" which is not going to work. Just run ghc -fllvm -keep-llvm-files -fforce-recomp src.hs (or manually modify src.hs and recompile it)....
The only instance for Info with any code is the one for Cat, so the only possible value of the second element of the tuple is the result of show (a :: Cat) which is invariably "Cat \"...\"". The Info instance for Dolphin came from GeneralizedNewtypeDeriving; it does exactly what...
haskell,configuration,ghc,cabal,cabal-install
Okay, I decided to just look at the source code and answer my own question. After diving through the cabal-install source code and ending up inside the GHC source I eventually found what I was looking for at the bottom of compiler/main/HscMain.hs: showModuleIndex :: (Int, Int) -> String showModuleIndex (i,n)...
haskell,ghc,scrap-your-boilerplate,ghc-generics
The short answer is, this isn't possible, because Functor requires that the changing type variable be in the last position. Only type constructors of kind * -> * can have Functor instances, and your Expr doesn't have that kind. Do you really need a Functor instance? If you just want...
Let's begin by reviewing how Dict and (:-) are meant to be used. ordToEq :: Dict (Ord a) -> Dict (Eq a) ordToEq Dict = Dict Pattern matching on a value Dict of type Dict (Ord a) brings the constraint Ord a into scope, from which Eq a can be...
linux,performance,haskell,virtual-machine,ghc
Be sure to add -H128 to your build command line after +RTS -s Your eval looks fine, so you are good to go there. If you really wanted to go after sluggishness on this VM, increase the thread priority on the VM (and the VM console slightly if you want)....
haskell,compiler-construction,compilation,ghc,abstract-syntax-tree
The Haskell source is first parsed into an AST of full Haskell, which is then typechecked. From then on, it gets desugared to Core, translated to STG, from there to Cmm to either assembly or LLVM code. All these phases are built on ASTs, there is no textual representation of...
You can't implement xor for modular numbers just by xorring the underlying bits; you'll get out-of-range numbers. For example: ghci> 9 `xor` 4 :: Integer 13 This is what the derived instance would do, which means it wouldn't work anyway. This sort of thing is why the constructor for Mod...
It is possible that you are using a sandbox, in which case you can see which packages are in the sandbox with, for example, cabal exec ghc-pkg list bytestring I haven't seen any language that checks for type safety across library versions. Why does haskell do that? There is no...
The tai parameter is fixed to Double because of your datatype. Change it to data Method a = Ndiv Int | Size a for example, then your function should typecheck, although you'll need a stronger constraint than Num, as cieling requires RealFrac. The type will be function :: RealFrac a...
I've read this answer, but I don't see any ..._rot0cw_closure in the assembly output. You need to name your module. e.g. add module Main where at the beginning* to get Main_rot0cw_closure in the generated assembly. * Strictly speaking, your module needs to export the function....
Yes, compiling with -fPIC helps. Here is how to do that. ghc-7.8.4/mk/build.mk: SRC_HC_OPTS = -H64m -O EXTRA_HC_OPTS = -fPIC SRC_CC_OPTS = -fPIC -O GhcStage1HcOpts = -fasm -O0 GhcStage2HcOpts = -fasm -O0 GhcLibHcOpts = -fasm -O2 GhcLibWays = v dyn DYNAMIC_GHC_PROGRAMS = YES DYNAMIC_BY_DEFAULT = NO SplitObjs = NO HADDOCK_DOCS =...
In simple terms, a value of type Int may be an unevaluated expression. The actual value isn't calculated until you "look at" the value. A value of type Int# is an evaluated result. Always. As a result of this, a Int a data structure that lives on the heap. An...
I think this should count as a bug in GHC, but there is a workaround. The default encoding for all handles in a GHC program (except those opened in Binary mode) is just the encoding accepted by the console with no error handling. Fortunately you can add error handling with...
haskell,memory,recursion,ghc,tail-recursion
I was putting the seq in the wrong place. It needs to be: n `seq` qr `seq` sr `seq` doChoose (n-1) (k-1) (qn * qr `rem` modulus * inv qk `rem` modulus, sn + sr - sk) Otherwise the call to seq isn't evaluated until reaching the base-case and a...
There is a confusion between GHC threads and OS threads. "A thread is represented by a TSO (thread-state object) by GHC […] Threads are run by Capabilities, which can be thought of virtual cores managed by GHC. Capabilities are, in turn, mapped to true operating system threads, or Tasks, though...
The let max = ... looks suspicious here: lPathFun !nodes !nodeID !visited = do UMV.write visited (fromIntegral nodeID) True let max = CM.foldM acc (0::Int32) (nodes V.! (fromIntegral nodeID)) UMV.write visited (fromIntegral nodeID) False max Your code is equivalent to: UMV.write ... True UMV.write ... False CM.foldM acc ... but...
I suppose the problem is that foos return value isn't actually polymorphic. foo itself is polymorphic but the returned value must exist at a specific type. Unfortunately, the type you want to use isn't available yet and cannot be brought into scope at foos call site because of the circular...
haskell,ghc,type-inference,ghci
This looks like the effect of Monomorphism Restriction (introduced because otherwise there were incoherent things in the language, and the language designers couldn't come up with something less ugly): if something looks like a value rather than like a function (with arguments), it can't be polymorphic. (Your fstGt0 has no...
haskell,optimization,ghc,unboxing
On my Ubuntu box, the relevant core code compiled to this 406168: 48 81 7b 07 3f 42 0f cmpq $0xf423f,0x7(%rbx) 40616f: 00 406170: 75 28 jne 40619a <c4fz_info+0x32> 406172: bf 52 e3 6d 00 mov $0x6de352,%edi 406177: be 90 65 6d 00 mov $0x6d6590,%esi 40617c: 41 be 18 6a...
My guess is that this is the culprit: instance Monad (EitherIO e) where return = EitherIO . return . Right x >>= f = join $ fmap f x However, join is defined as: join x = x >>= id However, in this way join and >>= get defined in...
This was a change introduced in GHC 7.10.1-rc1: GHC now checks that all the language extensions required for the inferred type signatures are explicitly enabled. This means that if any of the type signatures inferred in your program requires some language extension you will need to enable it. The motivation...
The closest we are able to get is a Class1 class that reifys the relationship between a class and a single superclass constraint as a class. It's based on the Class from constraints. First, we'll take a short tour of the constraints package. A Dict captures the dictionary for a...
haskell,memory,ghc,lazy-evaluation
In the second case your memory usage is not coming from storing the list but from building up unevaluated thunks from the use of succ x. succ is lazy, so calling succ x just allocates a new thunk on the heap. This thunk never gets evaluated because you never need...
This question is quite broad -- I'll address a few points, only. The proxy type variable is just a type variable of kind * -> *, i.e. the kind of type contructors. Pragmatically, if you have a function foo :: proxy a -> ... you can pass to it values...
haskell,profiling,ghc,haskell-platform
The preferred solution is to install cabal-install via your package manager. If you have an old version of cabal-install in your package manager, you can then use the old version to install the new version with a config in place, or even specify profiling directly on the command line via...
I made a mistake entryCursorPosition is a read only attribut and can't be set. The correct function to set the cursor position in a entry is : editableSetPosition entry (-1) Hoping it will be helpfull...
There is in fact a bug, and it will be fixed in the next release of GHC.
The GHC-specific module GHC.Stats provides a function getGCStats whichs returns (in IO) various GC statistics: getGCStats :: IO GCStats Retrieves garbage collection and memory statistics as of the last garbage collection. If you would like your statistics as recent as possible, first run a performGC. ...
linux,haskell,make,ghc,theorem-proving
Looks like paradox was written for a rather old version of GHC. You can fix all these "Could not find module" errors by using GHC version 7.8 or older and setting GHC = ghc -hide-package base -package haskell98 in the Makefile, though you will likely encounter more errors after that....
Yes, use ghc -hide-package evil-package. Or you can hide the package temporarily with ghc-pkg hide evil-package, and then undo it later with ghc-pkg expose evil-package.
haskell,linker,linker-error,ghc,cabal
You need to include the Paths_rlglue module in exposed-modules or other-modules like any other module in your project so that Cabal will link it. Cabal should be better about telling you what is going on, see https://github.com/haskell/cabal/issues/1746....
I haven't read more than a drop of the paper, which is well over my head, but I believe the problem is almost certainly caused by the type family. You have a function of type Vec a n1 -> Vec a n2 -> Vec a (Plus n1 n2) but type...
If you only want a more graceful error handling, you can use import Text.Read parseOuter :: Maybe Outer parseOuter = readMaybe "Outer { inner = Inner { x = 4, y = 4.5 } }" main :: IO () main = do case parseOther of Just x -> print x...
That's described in section 1.4 of GHC's users guide: The value of __GLASGOW_HASKELL__ (see Section 4.12.3, “Options affecting the C pre-processor”) for a major release x.y.z is the integer xyy (if y is a single digit, then a leading zero is added, so for example in version 6.8.2 of GHC...
Why does haskell store bytestring libraries in two different places. This is leading to compilation errors due to type/version mis-match. Well, no. The problem is that you have two versions of the bytestring library installed, period. It doesn't matter whether they are in the same package database or not....
you have to fully qualify No, not fully qualify. Consider: import qualified Algebra.Additive as Add myadd :: Add.C a => a -> a -> a That looks fairly readable to me. EDIT: Also consider making a superclass and treating that as an alias: class (Add.C a, Ring.C a) =>...
You could run myTransaction :: GNum -> GNum -> Int -> IO () myTransaction n1 n2 v = do y <- atomically $ do x <- readTVar n1 return (x + v) randomDelay atomically $ updateNum n2 y but be warned that this runs two atomic transactions. I.e., there might...
Perhaps you should set the encoding of the handle you're actually writing to. I don't know for sure, since I can't reproduce your problem, but something like this may do: withFile "asd.txt" WriteMode $ \h -> do hSetEncoding h utf8 hPutStr h "ćlččć" ...
haskell,math,ghc,number-theory
The cheap, cheesy way to make this compile is to add FlexibleContexts, then add KnownNat (k1 * k2) to the context of crt. Once I did this, I could successfully call it in ghci: > crt (3 :: Mod Integer 5) (5 :: Mod Integer 7) 33 Have fun working...
Although @Sebastian response is correct, yes you can {-# LANGUAGE ViewPatterns #-} import Prelude hiding (odd) data Peano = Zero | Succ Peano deriving Show data PeanoInt = Neg Peano | Pos Peano deriving Show odd :: PeanoInt -> Bool odd (Neg Zero) = False odd (Pos Zero) = False...
The rule of thumb is as follows: Make everything safe. If profiling reveals a performance problem in the overhead of FFI calls, carefully consider whether the semantics of unsafe are appropriate for the hotspot calls. If profiling has revealed a performance problem in the overhead of a safe FFI call...
haskell,ghc,deriving,ghc-generics
I'm using GHC 7.8.3 (from the Haskell Platform). Below is a cabal.config file with the specific versions used in the sandbox. constraints: aeson ==0.8.0.2, array ==0.5.0.0, attoparsec ==0.12.1.2, base ==4.7.0.1, bytestring ==0.10.4.0, containers ==0.5.5.1, deepseq ==1.3.0.2, dlist ==0.7.1, generic ==0.1.0.0, generic-aeson ==0.2.0.2, generic-deriving ==1.7.0, ghc-prim ==0.3.1.0, hashable ==1.2.2.0, integer-gmp ==0.5.1.0,...
Without FlexibleContexts all typeclass constraints on function definitions must have type variables. For example: add :: Num a => a -> a add = (+) Where a is the type variable. With FlexibleContexts enabled you can have any type inside a typeclass. intAdd :: Num Int => Int -> Int...
haskell,ghc,functional-dependencies,type-constraints
You are misunderstanding how type variables are bound. They are not bound by the tau type (the a -> a in your example), but an implicit binder based on the full phi type ((Bar a b) => a -> a). This binding can be made explicit with the ExplicitForAll GHC...
My understanding is that when you ask GHC to compile code for profiling, the binary interface to the code changes. (And also it gets linked against a different version of the RTS.) Since all code in the same program must have the same binary interface... well, that's why. To avoid...
Make sure that you're using runhaskell with the source file test.hs rather than the compiled binary test. If you've used something like ghc to create an executable file, you can just run that directly, with something like: ./test Be aware that test is probably not a good name for an...
The problem is with the indentation of your code. Use spaces for indentation. Indenting with 4 spaces is considered as a good practice. This code works perfectly: getNums = do putStrLn "enter a number (0 to terminate)" num <- getLine if read num == 0 then return [] else do...
Provided by Thomas & Daniel in the comments, it turned out I was: Impatient. Large chunks eventually show up with the pi function, it's just a bit slow on my simple old coding machine. Not handling buffering in any way. So after rewriting the main function: import System.IO main ::...