2,510
questions
1
vote
1
answer
77
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
189
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
89
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
52
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\...
5
votes
1
answer
60
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
81
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
97
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
26
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
121
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
79
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
164
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
51
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
98
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
58
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
79
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
98
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
0
answers
66
views
GHC libraries with FFI on Windows have "foreign export" symbols missing
I have the following Haskell source, from which I would like to compile a static library that can be linked into a C program:
{-# LANGUAGE ForeignFunctionInterface #-}
module Lib where
printHello :: ...
0
votes
1
answer
104
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
191
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
85
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
111
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
91
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 ...
3
votes
0
answers
63
views
libffi.so link issue for Haskell compiled executable on Linux platforms
I am working on a Haskell project where the final executable is dependent on the libffi.so.6 if it's being compiled on Ubuntu 18 and if I run it on Ubuntu 20 machine it fails stating it couldn’t find ...
4
votes
2
answers
74
views
Admissble type role overrides
In GHC Haskell, Map k v has a type role declaration for k to be nominal. This is because the user can otherwise coerce k to another type with the same representation but different Ord instance, ...
1
vote
1
answer
60
views
How to change the order of type application parameters for a constructor
I've got the following data type definition:
type DynamicF' :: k -> (k -> Type) -> Type
data DynamicF' k f where
DynamicF :: Typeable a => f a -> DynamicF' k f
The thing is, ...
7
votes
1
answer
95
views
Why does Data.Dynamic contain a witness instead of a typeclass constraint?
Data.Dynamic has the following implementation:
data Dynamic where
Dynamic :: TypeRep a -> a -> Dynamic
It has occurred to me that the following definition would be equivalent (at least I ...
0
votes
0
answers
41
views
cabal link error undefined symbol on windows
I worked on linux and macos without any cabal problems at all.
When I moved to windows I can't link even the simplest application:
> cabal --version
cabal-install version 3.10.2.0
compiled using ...
2
votes
1
answer
109
views
Haskell speed issue where executing both parts of a program takes significantly longer than either part alone
I have a Haskell program which has 2 lines of code in the main:
putStrLn $ "Day11: part1: " ++ show (sum $ bigManhattan 1 galaxies <$> pairs)
putStrLn $ "Day11: part2: " ++ ...
2
votes
1
answer
69
views
Haskell's polymorphic functions in different GHC version
I am developping vulkan app in haskell in MacOS (M2 gpu).
Code width = realToFrac (width (swapchainExtent :: Extent2D)) in following project (vulkan)
https://github.com/expipiplus1/vulkan/blob/...
0
votes
1
answer
77
views
Haskell - Cabal linker command failed when installing Text.Regex.Posix
I'm pretty new to working with Haskell. My professor is having us use it for class.
Currently working on Mac. While going through some tutorials, I found out I had to download the regex package for ...
6
votes
0
answers
48
views
Working around conflict between `c-source` name and GHC RTS name
I have some C source code that I am calling from Haskell using ccall FFI. To make the build process as easy as possible, I'd like to use Cabal to compile the C files, so I've added the sources to the ...
3
votes
1
answer
58
views
GHC API equivalent of adding a C/C++ file/object to the compilation
Say I have this GHC command:
ghc -ibuild/foreign/somelib \
-lstdc++ \
-outputdir "$buildDir" \
foreign/somelib/somelib.o \
src/Main.hs -o "$buildDir/Main"
The somewhat ...
4
votes
1
answer
85
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 ...
2
votes
0
answers
52
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
|]
...
3
votes
1
answer
50
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]
...
1
vote
2
answers
100
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 ...
1
vote
1
answer
72
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 ...
1
vote
0
answers
55
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 -&...
1
vote
1
answer
60
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 ...
2
votes
1
answer
162
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 ...
2
votes
1
answer
167
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, ...
3
votes
1
answer
89
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 ...
2
votes
1
answer
241
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 ...
0
votes
1
answer
72
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 ...
1
vote
0
answers
100
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\...
1
vote
1
answer
52
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 ...
3
votes
0
answers
126
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 ...
2
votes
1
answer
280
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 = [...
4
votes
2
answers
230
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 ...
1
vote
1
answer
156
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
.
.
}
...