51,804 questions
1 vote
1 answer
36 views
How to import a Haskell function in Python
I cannot fix this error. build.sh is trying to create a shared library but it fails: ~/Desktop/deepseek$ ./build.sh Building Haskell shared library... Loaded package environment from /home/success/....
-3 votes
1 answer
107 views
How to embed data equality information in Haskell's types?
I need help with some haskell syntax. I have a really long type signature and I need a quick way of making sure that the parts of it which are equal are represented in the signature itself. Signature: ...
2 votes
1 answer
54 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 #-} {-# ...
1 vote
2 answers
115 views
Replacing the element in the list with the specific index using `foldr` —— Exercise 1.19 of Essentials of Programming Language
Here is the question from Mitchell Wand's Essentials of Programming Language: Exercise 1.19 [⋆ ⋆] (list-set lst n x) returns a list like lst, except that the n-th element, using zero-based indexing, ...
-1 votes
1 answer
120 views
Is there a way to write a linear monad transformer?
I need a function of type linearJoin :: (ctx,Functor n,Functor m,Functor x) => (forall a. n (m a) -> x a) -> t n (t m a) -> t x a A bind version would look like this linearBind bindfun f k ...
2 votes
4 answers
199 views
Combining two associated type families
I'm looking into associated type families. As an own learning example, I try to model a small part of the x86 assembly language. This compiles: {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ...
Advice
0 votes
4 replies
126 views
Test Equality of Infinite Lists
In Haskell, how should one test the equality of two infinite lists? With finite lists, one might try: listEqual :: Eq a => [a] -> [a] -> Bool listEqual l0 l1 = and $ zipWith (==) l0 l1 But ...
4 votes
2 answers
111 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 ...
0 votes
1 answer
79 views
Haskell Foldr ADT from a List of Expressions into a single expression
So this is the data definition and my function. Task 3 Define addAll, which adds a list of expressions together into a single expression without introducing any 'junk'. You could use foldr since it ...
Best practices
5 votes
3 replies
150 views
Is there a way to tuck in Ord inside Applicative?
I had a nice idea of using applicative for nondeterministic financial modelling. Or maybe it is a simple case of sentization. So the basic example is to define newtype ValueRange. newtype ValueRange a ...
5 votes
2 answers
152 views
Ambigous type variable in tagless final mini language
Fur fun and education I'm trying to write a mini compiler with the final tagless method as described by Oleg Kiselyov in his paper Typed Tagless Final Interpreters. My grammar has expressions and ...
5 votes
1 answer
140 views
What is the formal name for GHC automatically adapting less-constrained functions to more-constrained rank-2 arguments? [closed]
Consider this Haskell code that compiles successfully: {-# LANGUAGE RankNTypes #-} -- Applies a polymorphic function to different types, expecting 3 constraints applyToMany :: (forall a. (Show a, Eq ...
4 votes
1 answer
115 views
Understanding usage of withFileBlocking with named pipes
The following program assumes that /path/to/mypipe is a named pipe, e.g. created via mkfifo /path/to/mypipe, with no readers/writers waiting yet, runs two threads, of which the main thread keeps ...
0 votes
1 answer
154 views
How do I make the "return" function from the Monad class return a phantom parameter?
MRE: module Temp where data Some r a = Thing r a instance Monad (Some r) where return :: a -> Some r a return a = Thing r a -- <- The is a phantom argument (somewhat like the s in ...
2 votes
2 answers
177 views
Merge every element of 2 lists of lists
Suppose, we have 2 lists of lists: a = [[1,2], [3,4]] b = [[5,6], [7,8]] We want to merge every element of the first list with every element of the second list and get: c = [[1,2,5,6], [1,2,7,8], [3,...