Skip to main content
Filter by
Sorted by
Tagged with
Best practices
0 votes
2 replies
21 views

I currently have this implementation: data RoseTree a = RoseTree a [RoseTree a] preorder :: Tree a -> [a] preorder (Tree x ts) = x : concatMap preorder ts instance Foldable Tree where foldr :: (...
Panic's user avatar
  • 93
2 votes
1 answer
56 views

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/....
success moses's user avatar
-3 votes
1 answer
115 views

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: ...
kesarling's user avatar
  • 2,318
2 votes
1 answer
54 views

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 #-} {-# ...
davidg's user avatar
  • 63
1 vote
2 answers
119 views

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, ...
YCH817's user avatar
  • 123
-1 votes
1 answer
120 views

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 ...
Ashok Kimmel's user avatar
2 votes
4 answers
201 views

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 ...
Jogger's user avatar
  • 1,783
Advice
0 votes
4 replies
126 views

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 ...
Geoffrey Warne's user avatar
4 votes
2 answers
111 views

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 ...
davidg's user avatar
  • 63
0 votes
1 answer
79 views

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 ...
charlotte chang's user avatar
Best practices
5 votes
3 replies
150 views

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 ...
Dominik G's user avatar
  • 614
5 votes
2 answers
152 views

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 ...
Jogger's user avatar
  • 1,783
5 votes
1 answer
140 views

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 ...
Thomas's user avatar
  • 6,364
4 votes
1 answer
115 views

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 ...
Enlico's user avatar
  • 30.3k
0 votes
1 answer
154 views

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 ...
kesarling's user avatar
  • 2,318
2 votes
2 answers
178 views

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,...
user4035's user avatar
  • 24k
3 votes
1 answer
93 views

I am currently writing common theorems of intuitionistic logic in Haskell using the Curry-Howard isomorphism: import Data.Void type a :> b = a -> b -- implies type a :+ b = Either a b -- or data ...
Zayd Mohammed's user avatar
2 votes
1 answer
94 views

I've been making progress with Chris Allen's Haskell book and I am stumped in an exercise as the title suggests. First of all, the binary tree is defined as such: data BinTree a = Leaf | Node (...
Κωστής Καρβουνιάρης's user avatar
5 votes
2 answers
134 views

I encountered a problem where my ram explodes and I really don't know why. the code to read a csv is: --module splitComma _ [] = [[]] splitComma False (',':t) = [[]]++splitComma False t splitComma ...
Agustin Bustos Barton's user avatar
4 votes
1 answer
120 views

I'm learning about Haskell and came across this concise, but weird, definition for a function that multiplies three numbers: volume :: Float -> Float -> Float -> Float volume = ((*) .) . (*) ...
zahiko's user avatar
  • 83
3 votes
2 answers
104 views

If in a terminal I enter mkfifo /tmp/pipe echo hello > /tmp/pipe (which blocks) and in another I run the haskell program main = readFile "/tmp/foobar" >>= putStr then I see it ...
Enlico's user avatar
  • 30.3k
3 votes
1 answer
84 views

I want to recursively collect arguments of a function to a tuple with nesting (the general idea is taken from here). I have a class with a function with polymorphic parameter (a, b). I want to make an ...
Dmitry Kapustin's user avatar
2 votes
1 answer
86 views

I'm reading the paper Selective Applicative Functors. So far I've read from page 16 out 29, and I think I've understood the gist of this abstraction, but I'm having some trouble with some basic ...
Enlico's user avatar
  • 30.3k
1 vote
1 answer
90 views

Take this simple program in Haskell {-# LANGUAGE OverloadedStrings #-} import Control.Exception (finally) import Control.Monad (forever) import Xmobar (tenthSeconds) import DBus.Client startServer' :...
Enlico's user avatar
  • 30.3k
1 vote
1 answer
81 views

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 ...
ron's user avatar
  • 9,458
1 vote
1 answer
65 views

Apart from the known safety concerns documented for unsafeFreeze / unsafeThaw, is there any issue using these functions with non-pinned backing data (that is, as I understand everything except Vector....
ron's user avatar
  • 9,458
3 votes
2 answers
107 views

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 ...
ron's user avatar
  • 9,458
1 vote
2 answers
169 views

Function fmap has two arguments: function and its argument(s). When I execute fmap for IO monad, it executes the second argument, but not the first: main = fmap (\_ -> print "def") (print ...
Dmitry Kapustin's user avatar
5 votes
3 answers
126 views

Let's say I am receiving a streaming response from a web service. I get the response in the shape of a ConduitT () (Either a b) m (). Now, let's say I know from the API documentation that the response ...
Jules's user avatar
  • 619
3 votes
1 answer
111 views

I have a testcase for a complicated function that for unclear reasons tends to hang on certain platforms. I would like to know which test inputs cause the hanging behaviour. I have tried to use ...
sjakobi's user avatar
  • 3,668
0 votes
0 answers
94 views

I started a new Yesod project with stack new blog yesodweb/postgres. The template generates an app/DevelMain.hs with a comment at the top that says that we can get faster dev reloads via stack ghci ...
doliver's user avatar
  • 1,046
0 votes
0 answers
70 views

I'm trying to set up Haskell in VSCode Windows by following this Better Programming Guide Everything worked fine except for the code formatting. I tried installing brittany using stack install ...
Timeless0007297's user avatar
0 votes
0 answers
70 views

Why is this slow fibonacciSequence :: Integral a => [a] fibonacciSequence = 0 : 1 : zipWith (+) fibonacciSequence (tail fibonacciSequence) -- in repl take 10000 fibonacciSequence but this ...
daikonradish's user avatar
2 votes
2 answers
140 views

This pertains to Emily's answer here: https://stackoverflow.com/a/13850560/2026752 ansMap :: M.Map Integer Int ansMap = M.fromAscList [(i, collatz i) | i <- [1..1000000]] where collatz 1 = 0 ...
daikonradish's user avatar
2 votes
1 answer
140 views

I'm trying to write a function that performs a binary operation on either floating-point numbers or integers. My attempt: data MyNum = F Float | I Int performBinaryOperation :: (Num a) => (a -> ...
Jacob Lockard's user avatar
0 votes
1 answer
80 views

I am trying to write a Twitch chat bot that will receive messages. The messages will be in JSON and be an object of two other objects, metadata (which appears to be mostly standardized across all ...
Jason Harrer's user avatar
0 votes
0 answers
48 views

I am learning parallel programming in haskell. My example code: module Quicksort where import Control.Parallel.Strategies import Control.Parallel qsort :: [Int] -> [Int] qsort [] = [] qsort lst@(...
kesarling's user avatar
  • 2,318
3 votes
2 answers
114 views

I'm still quite new to Haskell and don't have a great grasp of monads intuitively. I'm trying to write the function below: applyPandocFilters :: (MonadIO m, PandocMonad m) => Pandoc -> m Pandoc ...
paid50-face-pretty's user avatar
1 vote
1 answer
73 views

I have this datatype newtype Dimension a b = MkDimension b Whenever it is properly formatted (e.g. satisfies the format constraint), I want to derive a set of classes. I do not want a Dimension which ...
Ashok Kimmel's user avatar
0 votes
2 answers
196 views

A monad, I've been told, is a monoid of X in the category of endofunctors of X, where X is some category. Maybe is supposedly then a monoid, which means that it is: an object of a category, some ...
Erik's user avatar
  • 19
2 votes
0 answers
81 views

I have function (RSA encryption) where end result m depend on m1 and m2 where m1 and m2 can be computed in parallel. I tried to use par and pseq but the result is weak. Total time 20.062s ( 18....
Maq's user avatar
  • 427
1 vote
1 answer
132 views

I want to use print from chain of functions, but it doesn't work. getNext is called from inside app1, but print is not called from inside app2. Why? The output is just Just (39,40,41,"zzz") ...
Dmitry Kapustin's user avatar
1 vote
2 answers
91 views

I have a GADT like data GADT where Data :: a -> GADT and I want to implement a Show instance depending on where Show a exists. Intuitively, something like instance Show GADT where show (Data a)...
Maki's user avatar
  • 399
3 votes
0 answers
46 views

I have a program that does slightly different things on different OS/architectures. I'll use this example: main = do output <- readProcess "uname" [] "" print $ case ...
Koterpillar's user avatar
  • 8,288
2 votes
2 answers
100 views

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, ...
Jacob Bauer's user avatar
3 votes
2 answers
92 views

I was trying to define an integer type, and a typeclass that would allow operations on all Numberlike types. {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# ...
Ashok Kimmel's user avatar
2 votes
1 answer
128 views

I'm trying to setup the Neovim plugin https://github.com/mrcjkb/haskell-tools.nvim for a while now and I don't see any progress. I mostly want this plugin for Haskell CodeLenses, so that I can write a ...
h-c's user avatar
  • 54
4 votes
3 answers
127 views

I am trying to split my code into nice modules. However, while doing this, one of the classes I have in the imported module (Outer in Module 1 below) needs a constraint that is only known in the ...
Niek Janssen's user avatar
2 votes
1 answer
56 views

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 ...
Jacob Bauer's user avatar
1 vote
1 answer
97 views

I'm trying to use State Monad in a personal section of code in order to have a more natural code . The problem and the code section are the following ones . I'm trying to ask interactively a user to ...
Yago's user avatar
  • 445

1
2 3 4 5
1037