Questions tagged [ghc]

Glasgow Haskell Compiler is a state-of-the-art, open source compiler and interactive environment for the functional language Haskell. Use this tag for questions specifically about GHC and not about Haskell in general as almost everyone will be using it unless specified otherwise.

Filter by
Sorted by
Tagged with
4 votes
1 answer
50 views

Difference between newtypes and type synonyms for polymorphic constrained types

I know that newtypes can be used to avoid leaky abstractions when designing modular Haskell code. It's actually the only discussed difference between using newtypes versus type synonyms that I've ...
flupe's user avatar
  • 163
1 vote
0 answers
30 views

Can I attach Haddock comments to declarations in a `[d|…|]` declaration quote?

If I have a declaration quote passed to a Template Haskell function, something like someTHFunction [d| -- | Some documentation data SomeType = SomeConstructor | SomeOtherConstructor |] ...
Antal Spector-Zabusky's user avatar
3 votes
1 answer
37 views

Enable -Woverflowed-literals for custom numeric types

By default GHC enables the -Woverflowed-literals warning to emit a message if a literal's precision is too great for its type: OverflowedLiterals.hs:10:12: warning: [GHC-97441] [-Woverflowed-literals] ...
rampion's user avatar
  • 87.6k
1 vote
2 answers
86 views

Does GHC optimize the monoid operation over mempty?

If I write an instance of Monoid with a horrible complexity for its operation (<>), will GHC know that mempty <> x = x x <> mempty = x and avoid computing (<>) ? I'm also ...
141592653's user avatar
  • 496
1 vote
1 answer
61 views

GHC not deriving typeclass instances based on input type

I've lately been experimenting with dependent typing in Haskell through the Singletons library. To gain a better understanding I've been playing with my own implementations of various types without ...
CowNorris's user avatar
  • 432
1 vote
0 answers
40 views

How to print TraceStack in Haskell

I am learning haskell-language-server code. Add I cannot print out the tracestack. Following 3 approaches failed. defaultMain :: Recorder (WithPriority Log) -> Arguments -> IdePlugins IdeState -&...
zichao liu's user avatar
0 votes
0 answers
60 views

Different behavior in GHCI and GHC (Running radare2 pipe)

I am trying to get the example Haskell code of R2Pipe working. I have copied the R2Pipe.hs module file into my project and my main function looks as follows : module Main where import Control....
confusedandsad's user avatar
1 vote
1 answer
56 views

Why standalone deriving fails with rigid type on a record with existential quantification?

I am trying to compare associated types with existential ones, and wrote following snippet: {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE StandaloneDeriving ...
Daniil Iaitskov's user avatar
1 vote
1 answer
99 views

How do I get an error and warning count from GHC/Cabal/Stack?

If I run dotnet build in PowerShell to build a .NET project, at the end of the output, I see a message that tells me how many warnings and errors the compiler generated while building my project. I ...
Peter Bergman's user avatar
1 vote
1 answer
39 views

Haskell gnuplot not working displaying plot

I've been using the Glasgow Haskell Compiler (GHC) to learn Haskell. I installed the gnuplot package using Cabal (I used the command cabal install --lib gnuplot). I can load the gnuplot module, ...
Leo Schmidt-Traub's user avatar
3 votes
1 answer
76 views

Is there any possible benefit to SPECIALIZE a free type variable?

I think parametricity implies it can never help to specialize a free type variable (i.e. one with no class constraints), like a function :: Maybe a -> Bool. Are there any cases in the context of ...
jberryman's user avatar
  • 16.4k
2 votes
1 answer
201 views

Why is the assembly for this Haskell program fairly big w.r.t. equivalent C code? Or what am I doing wrong when compiling?

Once I asked Why is Haskell binary for simple "times 2" program so big (wrt e.g. C++)?, but that was duped to Small Haskell program compiled with GHC into huge binary. I've decided to ask a ...
Enlico's user avatar
  • 23.9k
0 votes
1 answer
68 views

Couldn't match expected type ‘t2 Integer’ with actual type ‘Integer’ on getter

So, I have a type called TotalDeleted that contains amount and equivalent. On stores the value in a Integer form other in a String for printing(also, I could use intercalate). The following code looks ...
Lukas Wilkeer's user avatar
1 vote
0 answers
51 views

Installing Haskell Stack builds and artifacts or GHC to a different drive than C:

Is there any good methods to install Haskell on a different drive than C: , such that when I run stack buildand stack test etc., it will not install a large number of files in C:\Users\myuser\AppData\...
Piskator's user avatar
  • 649
1 vote
1 answer
49 views

How to prnt a directory contents in Haskell

I'm using getDirectoryContents along toText derivative with fldmap. The error that occur is: IoString.hs:17:5: error: • Couldn't match expected type: FilePath -> IO () with ...
Lukas Wilkeer's user avatar
3 votes
0 answers
93 views

Large Haskell array prevents the compilation with GHC

I'm making an array of complex numbers in Haskell (array package) with the function array. The list of associations is big: 512 x 512 (of course I didn't fill it by hands). The file size is ...
Henri Labroche's user avatar
2 votes
1 answer
114 views

Could not load any module in Haskell [duplicate]

I made 3 Haskell scripts in a folder, and they import Text.Printf, Data.Char, Data.List, and System.Random: HaskellList.hs import Data.List import System.Random main :: IO () main = do let vb = [...
Prido1024's user avatar
4 votes
2 answers
98 views

How to set preference for `Text` and not `String` in Haskell

I run often in the problem that GHC interprets "some text" as String when I need Text in places where both are acceptable, only to find later the error in another use and forcing an explicit ...
user855443's user avatar
  • 2,626
1 vote
1 answer
85 views

How to suppress missing field warnings for record fields isomorphic to void?

Lets say I have a datatype like the following: data File' key generated value = File { id :: key Int, md5Hash :: generated Text, contents :: value Text, description :: value Text . . } ...
Clinton's user avatar
  • 22.5k
1 vote
0 answers
48 views

Haskell Type Signature `ThrowsError` vs `Either Error`? [closed]

I have seen some examples of Haskell code where Either Monad is "hidden" in the type signature using a type constructor. For example: In some code bases Haskell error handling type signature ...
Taimoor Zaeem's user avatar
1 vote
1 answer
31 views

GHC's readBin function from Numeric Library is not being recognised by GHCI

I am trying to use the readBin function from the Numeric Library but ghci is telling me that it is not in scope. Other functions like readOct and readHex are working. What could be the problem here? ...
Taimoor Zaeem's user avatar
0 votes
1 answer
99 views

Cross Compiling Haskell

How can I cross-compile Haskell to an ARM processor? I've already been able to cross-compile C, Go and Rust, so, I guess, this isn't a problem in my toolchain? I was able to run the configure script ...
tgvp's user avatar
  • 11
1 vote
0 answers
23 views

Cross-Compile Yesod app for aarch64 system on x86_64

as can be inferred from the title my goal is to deploy my Yesod app to an aarch64 Ubuntu server (using Keter). For this I would like to do compilation on my x86_64 debian machine, where I also develop ...
Shini's user avatar
  • 13
-2 votes
1 answer
82 views

Parse error, possiby identation or mismatch brackets

I'm writing a program in haskell but I doesn't get rid of an error: mountTree :: [Char] -> FilePath -> Int -> Either IO [FilePath] String mountTree promatiList toScan 0 = do b <- ...
Lukas Wilkeer's user avatar
4 votes
1 answer
90 views

How can I fix this Monomorphism Restriction warning

When I load the following code in ghci I get a Monomomorphism restriction warning with the suggested fix of Consider giving ‘pexp’ and ‘nDividedByPExp’ a type signature | 17 | (...
George Co's user avatar
  • 973
2 votes
1 answer
140 views

Haskell implementation of Determinant, Rank and Inverse Matrix calculation- input matrix size limitation

I'm new to Haskell. As a part of an academic course, I was requested to implement a function in Haskell that calculates the determinant, rank and inverse matrix of a given matrix. I use gaussian ...
Menish's user avatar
  • 21
6 votes
1 answer
187 views

Why some of the latest versions of ghc are not "recommended"?

Why so many "alive" versions of ghc at the same time? I believe that there is some technical reason but can't figure what exactly.. ghcup show 11 versions of ghc and one of those are marked ...
flavio's user avatar
  • 255
1 vote
1 answer
65 views

GHC 8.8.4 cannot suggests adding hashable even though it is already added

I wrote a program making use of the Hashset from the unordered-containers library. It works fine on my computer with GHC 9.2.4. For some reasons I'm trying to port it to GHC 8.8.4 as mentioned in the ...
ggegoge's user avatar
  • 81
6 votes
1 answer
89 views

Mixing type pattern matching and record syntax

Lets say I have the following (contrived example) for the function f: data T where T :: (Typeable a, Integral a) => { first :: a, second :: a } -> T printType :: forall a. Typeable a => ...
Clinton's user avatar
  • 22.5k
4 votes
1 answer
96 views

Is there a way to tell Haskell runtime to use memoization for functions with approximately the same inputs?

I have a Haskell function that takes several floats as inputs. This function is somewhat expensive to calculate, so it would be really nice if I could tell Haskell, "If all inputs are within +/- ...
James Strieter's user avatar
6 votes
2 answers
136 views

Is "hello" a thunk or in normal form?

Both 1 and "hello" are in normal form, thus are not thunks. So why does GHCi show that "hello" is a thunk? ghci> x = 1::Int ghci> :sprint x x = 1 ghci> x = "hello&...
Trung Do's user avatar
  • 115
3 votes
1 answer
132 views

I'm confused by Haskell's thunks

The wikibook says that: in this expression let z = (length [1..5], reverse "olleh") in ... z is a thunk. But this stackoverflow post says that the outermost layer of z is the data ...
Trung Do's user avatar
  • 115
0 votes
0 answers
107 views

I am having an issue with cabal install and cannot seem to install pretty-simple

So actually when I run install, it appears to be already installed: $ cabal install pretty-simple Resolving dependencies... Copying 'pretty-simple.exe' to 'C:\Users\ameen\.local\bin\pretty-simple.exe' ...
willnotgetbanned's user avatar
1 vote
1 answer
86 views

Why does the cost centre stack gets jumbled up in the Haskell profile file?

I am trying to profile my project in Haskell, but in the profile file (.prof) I am seeing the order in which the function stack is getting printed seems a little jumbled up. For example, when checking ...
ujjwal gupta's user avatar
3 votes
1 answer
110 views

Convert Num to Double in Haskell

I know about the existence of fromRational, fromInteger and fromIntegral. But is there a more generic function to convert any Num to the Double type? I'm also aware of the fact that Num is a set of ...
Otávio Augusto Silva's user avatar
2 votes
2 answers
154 views

Strictness and how to tell GHC/GHCi to just store a value in a variable once and for all

Apologies if this is a common question, I couldn't find anything similar, but I may just be too inexperienced to know the proper vocabulary. Here's an example of the fundamental problem in GHCi: -- ...
Syncrossus's user avatar
0 votes
0 answers
74 views

Cabal installing libraries give conflicting ghc-boot

I had to reinstall ghc on windows. After this succeeded, I am unable to install packages using cabal. I have done cabal install cabal-install. I can run tests, and build. However, installing any ...
someStudentCS's user avatar
3 votes
2 answers
95 views

Why can't type families/synonyms be partially applied, when we can work around the restriction anyway?

Consider the following Map type function: type Map :: (k1 -> k2) -> [k1] -> [k2] type family Map f l where Map _ '[] = '[] Map f (x : xs) = f x : Map f xs I can then define: type MkPair ...
Clinton's user avatar
  • 22.5k
1 vote
0 answers
145 views

Haskell GHC WebAssembly Backend - Memory Access Out of Bounds Error

I've been working on a browser-based Snake game using Haskell's GHC WebAssembly backend. The game runs initially but after a while, it crashes with the following error in the console: experiment.wasm:...
Benjamin Prevor's user avatar
4 votes
2 answers
115 views

What is the purpose of the "constructor header" in GHC?

This page here: https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/rts/storage/heap-objects suggests that every object in GHC has a header. So lets say I have: data X = X1 Int# | X2 Int# Int# My ...
Clinton's user avatar
  • 22.5k
1 vote
1 answer
39 views

Aeson 2 malformed field in cross-module import when Strict pragma is enabled

Please note that the issue described below doesn't happen in aeson 1.4.7 (stack LTS-16.31). This could be something related to ghc 9.2.7 perhaps. I have noticed that if I define a simple record in ...
Sal's user avatar
  • 4,332
0 votes
0 answers
67 views

hlock error when trying to install ghc on Linux

I am getting the error below when trying to upgrade the ghc. This btw also happens with ghc 9.2.7 - trying to install via stack (v2.9.1) resolver on CentOS 7 and x86_64, I get this error below (AWS VM)...
Sal's user avatar
  • 4,332
0 votes
0 answers
90 views

Issues with installing QuickCheck

I am having issues with installing QuickCheck for Haskell using GHC 9.4.4 and GHC 8.8.4, and I get the same output. Any assistance would be greatly appreciated! Resolving dependencies... cabal: Could ...
OwlZeroOne's user avatar
2 votes
0 answers
109 views

How to suppress warnings from external packages?

My stack build shows warning from external packages, like: happy > /tmp/stack-d6caed253e9f21bf/happy-1.20.0/src/ProduceGLRCode.lhs:224:12: warning: [-Wincomplete-uni-patterns] ...
Abhijit Sarkar's user avatar
1 vote
1 answer
66 views

Haskell GHC 9.4.4 compile error when -fllvm and -O2?

$ ~/.ghcup/ghc/9.4.4/bin/ghc --make -fllvm -O2 test.hs Loaded package environment from /home/dunham/.ghc/x86_64-linux-9.4.4/environments/default [1 of 2] Compiling Main ( test.hs, ...
igouy's user avatar
  • 2,557
3 votes
1 answer
64 views

Manual performGC hugely reduces memory footprint

My program uses the GHC API in IO, doing some computation inside a GhcMonad and forcing the result before returning it; something like this: main :: IO () main = do x <- runGhcT $ do x0 ...
Cactus's user avatar
  • 27.1k
3 votes
1 answer
80 views

Hide GHC base library to prevent pattern matching desugaring to GHC.Num.fromInteger use

I have created a replacement Prelude for use in teaching beginning Haskell students, called FirstPrelude. One of the aims is to expunge type classes from the standard library so that error messages ...
dorchard's user avatar
  • 1,198
0 votes
0 answers
74 views

Issue downloading HERMIT, selecting old GHC in GHCup

I'm trying to download the HERMIT tool using the command cabal install hermit. I dowloaded Haskell using GHCup. If I try to install with GHC 9.2.5 (recommended version by GHCup), I get errors like the ...
broland's user avatar
  • 11
1 vote
1 answer
38 views

Cost centres for Generic-derived instances?

According to +RTS -p time inherited, 90% of my execution time is spent running a Generic based instance MyClass MyType definitions, for a single class recursively over 100+ types/instances. I've tried ...
Filip Haglund's user avatar
1 vote
1 answer
403 views

Can't update ghc on Windows

Trying to update ghcup with ghc (ghcup install ghc 9.4.3) results in an error: [ Warn ] New cabal version available. To upgrade, run 'ghcup install cabal 3.8.1.0' [ Info ] verifying digest of: gs....
orsnmkhl's user avatar

1
2 3 4 5
50