Questions tagged [monadfix]
22 questions
40
votes
5 answers
Tying the Knot with a State monad
I'm working on a Haskell project that involves tying a big knot: I'm parsing a serialized representation of a graph, where each node is at some offset into the file, and may reference another node by its offset. So I need to build up a map from…

mergeconflict
- 8,156
- 34
- 63
21
votes
2 answers
Why can't there be an instance of MonadFix for the continuation monad?
How can we prove that the continuation monad has no valid instance of MonadFix?

Petr
- 62,528
- 13
- 153
- 317
21
votes
3 answers
Is it possible to implement MonadFix for `Free`?
http://hackage.haskell.org/package/free in Control.Monad.Free.Free allows one to get access to the "free monad" for any given Functor. It does not, however, have a MonadFix instance. Is this because such an instance cannot be written, or was it…

singpolyma
- 10,999
- 5
- 47
- 71
19
votes
2 answers
Using Cont to acquire values from the future and the past
I'm writing a brainfuck interpreter in Haskell, and I came up with what I believe to be a very interesting description of a program:
data Program m = Instruction (m ()) (Program m)
| Control (m (Program m))
|…

Dan Burton
- 53,238
- 27
- 117
- 198
16
votes
1 answer
Bug in Data.Map implementation?
I've stumbled upon something that I'm guessing is a bug in Data.Map, but which is also quite possibly a bug in my Haskell knowledge. Hoping somebody can clarify which it is :)
Please reference this gist. I'm serializing a circular linked list…

mergeconflict
- 8,156
- 34
- 63
14
votes
2 answers
Is there an instance of Monad but not of MonadFix?
The question is mostly in the title. It seems like mfix can be defined for any monadic computation, even though it might diverge:
mfix :: (a -> m a) -> m a
mfix f = fix (join . liftM f)
What is wrong with this construction? Also, why are the Monad…

Mokosha
- 2,737
- 16
- 33
13
votes
1 answer
Can a monadic rose tree have a MonadFix instance?
Given
newtype Tree m a = Tree { runTree :: m (Node m a) }
data Node m a = Node
{ nodeValue :: a
, nodeChildren :: [Tree m a]
}
Is there a valid MonadFix instance?
My attempt was
instance MonadFix m => MonadFix (Tree m) where
mfix f = Tree…

ocharles
- 6,172
- 2
- 35
- 46
12
votes
1 answer
Is a lazy, breadth-first monadic rose tree unfold possible?
Data.Tree includes unfoldTreeM_BF and unfoldForestM_BF functions to construct trees breadth-first using the results of monadic actions. The tree unfolder can be written easily using the forest unfolder, so I'll focus on the latter:
unfoldForestM_BF…

dfeuer
- 48,079
- 5
- 63
- 167
11
votes
1 answer
Any methods for recovering enough laziness to tie the knot in a monad?
I want to write a slick bit of code (saving me much time to implement otherwise) by tying the knot. It goes roughly like this,
n <- myinstr n x
where in theory, myinstr should run x to get a value, which will become n. myinstr, which runs inside a…

gatoatigrado
- 16,580
- 18
- 81
- 143
10
votes
1 answer
MonadFix in strict language
I'm working on camlp4 extension for haskell-like do notation in Ocaml, and trying to figure out how GHC compiles recursive do-bindings (enabled with -XDoRec).
I wonder if it possible for monadic fixpoint combinator to exist in strict language (like…

John Rivers
- 1,307
- 10
- 20
7
votes
2 answers
MonadFix instance for interpreter monad transformer generated by FreeT?
I have a simplified version of the standard interpreter monad transformer generated by FreeT:
data InteractiveF p r a = Interact p (r -> a)
type Interactive p r = FreeT (InteractiveF p r)
p is the "prompt", and r is the "environment"...one would…

Justin L.
- 13,510
- 5
- 48
- 83
6
votes
2 answers
MonadFix instance for []
The instance is defined as
instance MonadFix [] where
mfix f = case fix (f . head) of
[] -> []
(x:_) -> x : mfix (tail . f)
But I'm failing to grasp the intuitive meaning behind it with respect to the [] monad seen as…

Petr
- 62,528
- 13
- 153
- 317
6
votes
2 answers
MonadFix instance for Put
A simple question, I hope: The binary package defines two types, Get and Put. The former is essentially a state monad, and the latter is essentially a writer. Both state and writer have reasonable MonadFix instances, so I'd expect that Get and Put…

mergeconflict
- 8,156
- 34
- 63
5
votes
1 answer
typeclass for repetitive actions until fixed point
i noticed a common pattern of executing an action until it stops having certain effects, when one knows that this signifies a fixed point (ie, there can be no future effects). is there a typeclass for this?
is this covered by MonadFix? looking at…

user1441998
- 459
- 4
- 14
4
votes
3 answers
MonadFix instance for Rand monad
I would like to generate infinite stream of numbers with Rand monad from System.Random.MWC.Monad. If only there would be a MonadFix instance for this monad, or instance like this:
instance (PrimMonad m) => MonadFix m where
...
then one could…

Tener
- 5,280
- 4
- 25
- 44