All Questions
Tagged with haskell functional-programming
3,314 questions
1
vote
3
answers
136
views
In the context of STM, what does a transaction log conceptually look like, and how does it evolve when the transaction succeeds after a few retries?
For instance consider this function, that could be used in a WM to allow moving a window from one desktop to another on a given display,
moveWindowSTM :: Display -> Window -> Desktop -> ...
3
votes
1
answer
62
views
How do let and case differ in terms of lazyness?
How do let and case differ in terms of lazyness? Where do I find the information myself? And how do I experiment with it in ghci?
Some context
This incomplete piece of code is an excerpt from
Parallel ...
2
votes
1
answer
66
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
2
answers
66
views
Clarification on the importance of the immutability of the state inside an MVar in the context of concurrency
In Parallel and Concurrent Programming in Haskell by Simon Marlow, at pages 133 and 134 the following code is shown:
type Name = String
type PhoneNumber = String
type PhoneBook = Map Name ...
2
votes
1
answer
99
views
Why should bracket's first argument perform at most one blocking operation?
In Parallel and Concurrent Programming in Haskell by Simon Marlow, the implementation of bracket is shown,
bracket
:: IO a -- ^ computation to run first (\"acquire resource\")...
3
votes
3
answers
105
views
Does throw behave the same as throwIO, if instantiated as IO a?
I'm reading Parallel and Concurrent Programming in Haskell by Simon Marlow, and I initially read this suggestion fairly lightly,
It is always better to use throwIO rather than throw in the IO monad ...
3
votes
1
answer
60
views
Unresponsive ghci terminal [duplicate]
I read variables are immutable in haskell and something like the following does not work in haskell.
x = 30
x = x+1
But I still tried this to see what the compiler returns and I got the following :
...
2
votes
1
answer
59
views
Fixing a Haskell Generator's andAlso Function: Inconsistent Test Results
I'm working with a Haskell implementation of generators for a homework. I have an andAlso function that's supposed to add an additional predicate to a generator, but it's not working correctly in all ...
1
vote
2
answers
103
views
Is there a data type with two Functor instances and two Applicative instances, the latter with either 1 pure and 2 ap or vice-versa?
I came across this answer, where the claim that
A Functor instance is unique
left me a bit puzzled.
Ok, I think [] can be a Functor only in 1 way, but (,) can surely be made a Functor in 2 symmetric ...
4
votes
2
answers
189
views
How Haskell's thunks are so efficient?
The following Haskell implementation of Fibonacci runs in linear time:
fib = 0 : 1 : zipWith (+) fib (tail fib)
From what I understand fib calls are thunks here, so they are evaluated progressively ...
3
votes
1
answer
101
views
Does there exist a mathematical formalism which uniquely determines ADT structure given some data?
Suppose I have a type for fruit and I want to represent two types of watermelon, seedless and "seedful". Pretend we want to keep track of something about the seeds (perhaps their color). So ...
5
votes
1
answer
80
views
Is there a simple recursive analogue of this breadth-first binary tree deserialization function in Haskell?
I am interested in methods for serializing and deserializing a binary tree in breadth-first order. The first part, serialization, is equivalent to performing a levelorder traversal where we preserve ...
0
votes
1
answer
93
views
What determines the the lifetime of the process spawned via System.Process.createProcess?
tl;dr
If I run in the shell either this
$ grep hello
or this
$ socat tcp-listen:12345,fork -
the result is the same, i.e. the program blocks, waiting for standard input.
Why, wrapping those two ...
2
votes
3
answers
109
views
How can I lazily forward text to shell program and lazily get output back from it?
(This is a follow up to a previous question.)
I want to write a Haskell program that forward its standard input to grep's (or another Linux program, fwiw) standard input, and then collects grep's ...
1
vote
1
answer
82
views
Why can't print text passed via std input to createProcess-ed process?
Looking for usage examples of what's in System.Process, I landed at this page.
Here's an excerpt of the code I found there:
import System.IO
import System.Process
main = do
(Just hin, Just hout, ...