Skip to main content

All 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 -> ...
Enlico's user avatar
  • 28.9k
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 ...
Enlico's user avatar
  • 28.9k
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 = ...
Enlico's user avatar
  • 28.9k
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 ...
Enlico's user avatar
  • 28.9k
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\")...
Enlico's user avatar
  • 28.9k
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 ...
Enlico's user avatar
  • 28.9k
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 : ...
Akash Arjun's user avatar
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 ...
Simon Abadi's user avatar
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 ...
Enlico's user avatar
  • 28.9k
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 ...
itarato's user avatar
  • 875
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 ...
Brendan Langfield's user avatar
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 ...
Brendan Langfield's user avatar
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 ...
Enlico's user avatar
  • 28.9k
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 ...
Enlico's user avatar
  • 28.9k
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, ...
Enlico's user avatar
  • 28.9k

15 30 50 per page
1
2 3 4 5
221