2,537 questions
4
votes
0
answers
74
views
+100
Ensuring specialization while preventing inlining
disjointCollisions :: Eq k => Word -> Array (Leaf k a) -> Word -> Array (Leaf k b) -> Bool
I would like this function to be specialized (to arbitrary unknown key types k) but never ...
2
votes
1
answer
64
views
ghc gives error for something that's allowed in GHC.Internal.System.Posix.Internals
The following program gets the error:
"Illegal term-level use of the type constructor or class ‘IOError’"
even though it's right out of the source to ghc:
{-# LANGUAGE Trustworthy #-}
{-# ...
4
votes
2
answers
112
views
GHC can't avoid module cycle with class definitions
Problem: Can't avoid a module cycle with class definitions in Haskell.
Foo.hs contains:
module Foo where
import {-# SOURCE #-} Bar
class FooClass a where
...
myBar :: BarClass -> a -- use a ...
1
vote
1
answer
81
views
Under what circumstances can a write to a Haskell unsafeThaw-ed array/vector result in a segfault (via lost GC root)?
This question tries to collect the full picture if/when a stale object reference can happen from an old-gen (immutable) array referring a newer-gen object, from fragments of information.
Preface: was ...
3
votes
2
answers
107
views
Does GHC specialize data constructors, or how to design for such a usecase
I'm familiar with the SPECIALIZE pragma, or INLINE/INLINABLE that might enable automatic specialization at the use-site. But those are about specializing functions for type variables taking special ...
2
votes
2
answers
103
views
Cabal not recognizing Include/Header File Directories for FFI project
So I have a project in Haskell, and I was using make to build it, but then I switched the project over to use Cabal as someone recommended to me on another Stack Overflow post. It is an FFI project, ...
2
votes
1
answer
56
views
GHC(Haskell) not picking up imports from makefile
I have been making a Haskell project that I want to continue on in C at some point through the FFI. I wanted to create a makefile to compile all the source with Clang for C and GHC for Haskell.
The ...
7
votes
2
answers
216
views
What is wrong with this closed type family in GHC2021-GHC2024 as compared to Haskell2010?
In Haskell in Depth, Chapter 11, there's an example aimed at avoiding character escaping in GHCi, which is what happens automatically when you enter print "ë", as it'll be printed like "...
7
votes
1
answer
197
views
Redundant pattern matching slowing down our Haskell program
We are working on some programs that do rewriting logic, where there is a
state (often complex), a set of rules that match certain patterns in this
state, and strategy for applying these rules to ...
2
votes
1
answer
73
views
GHC.Record : Record data type may not be a data family
I would like to create a virtual record field "r" for the red component of a color using the Color package. This package uses a data family Color.
I tried to write the following :
import GHC....
4
votes
1
answer
125
views
What does `break<N>` mean in GHC Core?
Using GHC 9.6.2 and looking at the GHC Core output, I see a lot of
break<N>, where N is a small integer. What does this mean?
For example, from a source definition:
type Store = Map Id Integer
...
4
votes
2
answers
120
views
How to understand constraints of PFunctor in categories library
How to understand p r -> t and p t -> r in PFunctor p r t | p r -> t, p t -> r?
https://github.com/ekmett/categories/blob/4a02808d28b275f59d9d6c08f0c2d329ee567a97/old/src/Control/...
2
votes
1
answer
80
views
How can GHC's fairness guarantee not show up if a thread is descheduled while it is not holding the MVar?
In Parallel and Concurrent Programming in Haskell by Simon Marlow, chapter 7 starts at page 125 with this example,
import Control.Concurrent
import Control.Monad
import System.IO
main :: IO ()
main = ...
1
vote
0
answers
47
views
Visual Studio Code Haskell extension fails to find ghc version
I get following error in VSCode:
However, when I run this command in shell manually it works fine:
% stack --stack-yaml /home/user/haskell/h5/stack.yaml exec ghc -- --numeric-version
9.8.2
My stack....
4
votes
2
answers
146
views
Is it possible to define a symmetric typeclass?
Consider the following typeclass for defining equality between values of heterogenous types:
class HEq a b where
heq :: a -> b -> Bool
We can define an instance for Int and Bool as follows:
...
0
votes
1
answer
83
views
"Could not find module ‘GHCi.GhcApiCompat’." which installing `haskell-dap ghci-dap`
Below are my ghcup config -
I've I've created haskell project using stack with command stack new stack-hls-dbg-demo.
I then updated snapshot.url as below so that it uses ghc-9.10.1-
snapshot:
url: ...
0
votes
1
answer
77
views
Does the behavior of these two function differ in any way that justifies GHC compiling them down to different object code?
Here's a module:
module Foo where
foo ws = let ws' = take 3 $ ws ++ repeat mempty
x = ws' !! 0
y = ws' !! 1
z = ws' !! 2
in [x, y, z]
and here's ...
0
votes
1
answer
85
views
Does using undefined as the callstack result in a compiler error?
I was just trying out some stuff with the ImplicitParams language extension when I typed this code:
let ?callStack = undefined in undefined and it caused a compiler panic:
panic! (the 'impossible' ...
3
votes
1
answer
120
views
Does GHC allow newtypes to have existential type variables?
In the GHC manual, section 6.4.6 Existentially quantified data constructors, it says (second to last bullet point on the page), “You can’t use existential quantification for newtype declarations.”
In ...
0
votes
0
answers
79
views
GHC unable to find mingw/include directory on Windows
Today I used ghcup to automatically installed all haskell tool chains. When I entered ghc -Wall C:\2.hs -fforce-recomp,the response is:
[1 of 2] Compiling Main ( C:\\2.hs, C:\\2.o ) clang:...
3
votes
2
answers
103
views
How to expose coercions only one way?
Consider this somewhat silly datatype:
type data AllowPrimesOnly = PrimesOnly | AllNumbers
data Number (allowPrimesOnly :: AllowPrimesOnly) where
One :: Number AllNumbers
Two :: Number ...
1
vote
1
answer
997
views
Error occured while (re-)installing GHC and setting up the VSCode Haskell Plugin
I was trying to setup the Haskell Plugin for VSCode and I had two seperate problems while trying.
First: The original error I faced while setting up the Haskell Plugin in VSCode was:
HLS does not ...
0
votes
0
answers
54
views
How to exclude field record wildcard imports from ghc -Wmissing-import-lists?
I'd like to get the behavior of -Xmissing-import-lists but exclude record field wildcard imports.
Example: $ ghc -XNoImplicitPrelude -Wmissing-import-lists {a,b,c}.hs
a.hs:
import Prelude (putStrLn, ...
4
votes
1
answer
103
views
Why can't constructors have required type arguments?
Let's say I define the following datatype:
data fmt :* (n :: Nat) where
Rep :: fmt -> fmt :* n
Using RequiredTypeArguments, I can define a function that takes the n parameter as a required ...
1
vote
1
answer
42
views
Is GHC strict field packing the same as using unboxed types explicitly?
I believe if I make a constructor like:
data MyThing = MyThing
Word8#
Word8#
Word8#
Word8#
GHC (with optimisations turned on) will now pack the unboxed words within one word, instead of ...
1
vote
1
answer
57
views
How would I make GHC.Ptr an instance of Monad?
This is what I have so far:
instance Monad Ptr where
return = pure
(>>=) (Ptr t) f = f t
The error being thrown is:
• Couldn't match a lifted type with an unlifted type
When ...
1
vote
1
answer
81
views
Source code positions after CPP macro expansion
I have the following Haskell file that contains a CPP macro.
#define FOO( x, y ) x ++ y
foo =
FOO("a",
"b"
++ "c")
bar = 1
When I call cpphs on this ...
1
vote
1
answer
78
views
Running an executable with `cabal` in an environment that contains the `cabal`-managed package DB
I have a program A that internally calls GHC-as-an-API to compile some other Haskell module B. B has external dependencies (incl. compile-time plugins) that are recorded in the .cabal file as ...
4
votes
2
answers
289
views
GHC Warning: Non-exhaustive Pattern Match for List Despite Explicit Match on Empty List
I’m trying to write a simple Haskell function that distinguishes between an empty list and a non-empty list. Here’s my code:
{-# LANGUAGE OverloadedLists, RebindableSyntax #-}
import Prelude (Int, IO,...
1
vote
1
answer
109
views
How GHC captures the enviroment of variables when lambda expressions are used by value or by reference?
In this stackoverflow post there is code in C++ that tries to mimic associated types. When the lambda functions capture the environment(closure) using by reference capture the code compiles but fails ...
5
votes
1
answer
281
views
Simple recursive sum when compiled from Haskell to WASM is quadratic
The following Haskell funcion:
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Data.Word (Word32)
sum' :: Word32 -> Word32
sum' 0 = 0
sum' n = n + sum' (n-1)
foreign export ...
5
votes
1
answer
103
views
`getLabel` or `fromLabel`
The GHC documentation for OverloadedLabels here shows examples like
Leading capital letters: #Foo equivalant to getLabel @”Foo”
Should getLabel be fromLabel?
AFAIK getLabel is for creating unnamed ...
0
votes
1
answer
76
views
How to fix missing dependencies after deleting GHC's snapshots?
My C: drive was full, so I decided to remove all Haskell snapshots older than two month, knowing it could cause trouble.
And it did :
ghc-9.8.2.exe: addLibrarySearchPath: \\?\C:\sr\snapshots\d22c45cb\...
7
votes
2
answers
278
views
What determines what GHC (and Cabal, and HLS, ...) version is marked as "recommended" in GHCup?
I tend to stick to "recommended" versions:
┌──────────────────────────────────GHCup──────────────────────────────────┐
│ Tool Version Tags Notes ...
2
votes
0
answers
100
views
Possible explanations for an operation hanging indefinitely with a redundant constraint?
During a GHC upgrade we noticed one particular test case seemed to just hang forever (at runtime, not compile time). In searching for a looping bottom value lurking somewhere I found a startling fact, ...
2
votes
2
answers
276
views
Confusion between GHCup and Cabal as regards versions of installed packages (system-wise and in specific cabal projects)
This is what I see when I run ghcup tui in a terminal in $HOME:
┌──────────────────────────────────GHCup──────────────────────────────────┐
│ Tool Version Tags ...
0
votes
0
answers
34
views
Compiling project errors within a docker container targeting linux/amd64
I've been developing a side project (a small web app). I'm developing on a Macbook M1 Pro, however, I need to compile it to test against a linux/amd64 environment. I'm trying to use docker for that. I ...
3
votes
0
answers
271
views
Can I compile on Linux and target Windows?
Yes, in principle the present question is a duplicate of this one, but that's been asked and answered 12 years ago. The answer might have changed in the meanwhile. And indeed the material I linked to ...
2
votes
1
answer
152
views
Is there a way to set command line options at the top of a Haskell file?
I have some Haskell source files with which I interact with and I was wondering:
Is there a way to set command line options at the top of the file?
I refer to GHCi command line options that we use ...
6
votes
1
answer
281
views
How "auto lift" is implemented in Haskell?
I'm new to Haskell and learning about Monad Transformer. I found that lift can be omitted when operating on an inner monad in a monad stack. For example:
type Foo = ReaderT String (WriterT String ...
2
votes
1
answer
72
views
How to promote value into type with withKnownNat
I found functions withKnownNat and withSomeSNat in GHC.TypeNats. According to their signatures it is possible to apply function to a dynamic type parameter. If it is not possible then the purpose of ...
5
votes
2
answers
123
views
Why does nullary constructors in GHC Haskell take two machine words?
I experimented with the closureSize# primitive in GHC. Here I define the helper function I use (x is forced using a bang pattern, so what I am measuring should be the data constructor closures ...
1
vote
1
answer
110
views
How to define Generic instance manually?
It is assumed that instances of GHC.Generic class for data types should be generated automatically by GHC via deriving mechanism, but it is not working for row-types and anonymous records with ...
5
votes
1
answer
116
views
Rewrite rules with typeclass constraints
There's been a couple of previous questions about rewrite rules that have typeclass constraints, but they seem to involve higher-rank polymorphism. Here, I have a much more "vanilla" ...
1
vote
1
answer
221
views
How do I create a GHC package environment file that's equivalent to not having one?
When using GHC without a package environment file, you'll be able to use several libraries that it ships with, such as containers and text. When you do have a package environment, though, you can only ...
0
votes
1
answer
277
views
How to use GHC’s `ReadPrec`?
The documentation for GHC.Read describes readPrec only by:
Proposed replacement for readsPrec using new-style parsers (GHC only).
Other functions, types, etc. have no documentation at all. How do I ...
0
votes
1
answer
379
views
Homebrew error when installing GHC: linker does not have option `-no_fixup_chains`
I was trying to install GHC with homebrew (since Xcode require MacOS 13.5 and up but I'm still on 10.15). The installation error is as follows:
...
==> ./configure --prefix=/private/tmp/ghc-...
3
votes
1
answer
120
views
Why does Cabal, unlike GHC, not automatically enable GeneralizedNewtypeDeriving if I explicitly enabled DerivingStrategies?
From the documentation I'm inclined to think that if I enable the DerivingStrategies extension, I don't need to enable GeneralizedNewtypeDeriving or DeriveAnyClass, nor any other extension that I ...
0
votes
0
answers
134
views
Understanding and Optimizing Generational Garbage Collection in Haskell
When a program initializes, the mutator allocates memory space for new small objects in the nursery. The nursery serves as a buffer to maintain recently created objects. If these objects remain alive ...
0
votes
2
answers
135
views
Run cleanup function in multiple Haskell child threads when POSIX Signal sent (SIGTERM etc)
TL;DR - how do I make the following work in Haskell:
Send a SIGTERM to a long-running program with many active threads (each working on a job)
Get all child threads run a cleanup function (updating ...