51,801 questions
-3
votes
0
answers
65
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 ...
Advice
0
votes
4
replies
112
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 ...
0
votes
1
answer
76
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 ...
5
votes
2
answers
146
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 ...
4
votes
1
answer
105
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 ...
2
votes
2
answers
152
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,...
2
votes
1
answer
86
views
On implementing map in terms of fold for a binary tree in Haskell
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 (...
4
votes
1
answer
115
views
How does the point-free expression ((*) .) . (*) work in Haskell?
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 = ((*) .) . (*)
...
3
votes
1
answer
76
views
Polymorphic function in class and polymorphic instance: how to bind parameter types?
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 ...
1
vote
1
answer
85
views
Understanding behavior of DBus with respect to killing the process that used DBus to register a name
Take this simple program in Haskell
{-# LANGUAGE OverloadedStrings #-}
import Control.Exception (finally)
import Control.Monad (forever)
import Xmobar (tenthSeconds)
import DBus.Client
startServer' :...
1
vote
1
answer
62
views
Any memory safety concerns when using Haskell's vector unsafeFreeze / unsafeThaw on unpinned vector?
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....
1
vote
2
answers
163
views
Execution or evalution: any rules?
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 ...
3
votes
1
answer
109
views
Which test inputs cause my QuickCheck property to hang? (`QC.within` is insufficient to break the loop)
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 ...
0
votes
0
answers
52
views
How to configure brittany in Visual Studio Code Windows?
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 ...
2
votes
2
answers
138
views
Adding a single variable to the function signature makes code significantly slower
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
...
0
votes
1
answer
80
views
Haskell JSON Web API Generalization
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 ...
3
votes
2
answers
109
views
How to use Haskell `do` notation with multiple monad constraints
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
...
0
votes
2
answers
194
views
How is Maybe a monad in Haskell?
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 ...
1
vote
1
answer
131
views
Why can't I print from chain of functions?
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") ...
3
votes
0
answers
46
views
Merging hpc coverage from multiple architectures
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 ...
3
votes
2
answers
89
views
Is there a way to use a kind level class with type families?
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 #-}
{-# ...
4
votes
3
answers
125
views
Why can't Haskell unify my types when using a constraint as class parameter?
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 ...
1
vote
1
answer
97
views
State Monad in Haskell . How to adapt functors, applicatives and monads to characteristics and Die Rolls
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 ...
5
votes
1
answer
152
views
Can I reify class methods from within an instance in Template Haskell?
I have a class called Cls. In one of the instances of Cls, in one of the methods, I want to do some code analysis from within template haskell. I have to run a reify to start this inspection. Full ...
0
votes
1
answer
58
views
Haskell Parsec Parser giving strange error
I am having trouble getting the following code to work. I got it to work originally, then I changed it so all the Nonterminals also have positions. And I added the method parseLexeme that transforms ...