Questions tagged [monadfix]
22 questions
3
votes
3 answers
Understanding the sliding law of MonadFix
I intuitively understand the purity, tightening, and nesting laws of MonadFix. However, I'm having a hard time understanding the sliding law.
mfix (fmap h . f) = fmap h (mfix (f . h)) -- for strict h
My first question is that if h has to be strict…

Aadit M Shah
- 72,912
- 30
- 168
- 299
2
votes
2 answers
Haskell: monadic fixpoint on RWS is looping if traversing on argument
I am writing a program which involves RWS for tracking mutable state and producing some log. My purpose is to define a computation that evaluates some action, gathers the aftercoming state and depending on it appends something to the beginning of…

radrow
- 6,419
- 4
- 26
- 53
2
votes
3 answers
Mutually recursive evaluator in Haskell
Update: I've added an answer that describes my final solution (hint: the single Expr data type wasn't sufficient).
I'm writing an evaluator for a little expression language, but I'm stuck on the LetRec construct.
This is the language:
type Var =…

Tom Lokhorst
- 13,658
- 5
- 55
- 71
1
vote
2 answers
Why is `mfix` not total in `MaybeT`
The transformers implementation of MonadFix for MaybeT fails if the function ever evaluates to Nothing. Why is Nothing not propagating over mfix?
mfix' :: MonadFix m => (a -> MaybeT m a) -> MaybeT m a
mfix' f = MaybeT $ mfix $ \case
Nothing ->…

fakedrake
- 6,528
- 8
- 41
- 64
1
vote
1 answer
Duplicate EDSL code generated with RecursiveDo in Haskell
Using ghc v8.0.1, compiled with -O2 flag.
I'm having a problem with RecursiveDo (mdo). There are two slightly different functions that should produce the same output, but they don't.
The following function produces the correct output:
proc2 ::…

Glaukon
- 321
- 3
- 12
0
votes
1 answer
How to implement MonadFix instance of an IO-like type in JS?
I am completely lost in trying to translate the following Haskell code into Javascript:
instance MonadFix IO where
mfix f = do
var <- newEmptyMVar -- 1
ans <- unsafeInterleaveIO $ takeMVar var -- 2
result <- f…
user5536315
0
votes
0 answers
What is the meaning of tilde in lambda expression?
On the 7th page of this book there is a tilde (shown by red circle in the picture below) in the definition of toggle. What does the tilde mean ?

jhegedus
- 20,244
- 16
- 99
- 167