-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
state_t + error_t example? #4
Comments
state_t:run(Result, S) is either {ok, {A, State}} or {error, Reason} |
thanks for hint, but that does not work as I would expect (although I have to admit that I'm having some difficulty understanding how this is supposed to work). What I have tried is:
But this fails in pour_on_water with:
|
Just use
type of monad_state:modify is (s -> s) -> StateT s Either e a -> StateT s Either e () |
monad transformer is a concept from Haskell |
That doesn't make send, learning Haskell does not help anyone to understand how to use your library with Erlang. I understand that there is a difference between the ordering of the Error and State monade, but that still doesn't help me to get my example running. The sample might not be useful in itself, but it demonstrates what I want to achieve. A monad that applies the state modification no matter whether the function returned It would be extremely helpful if you could help with a working example of how this can be achieved with your library. Reading through all the unit tests has not yielded anything close to that. |
Or could it be that what I want to achieve is not doable with this library? In my quest for a sample I found code in one of your repositories that would have benefited from such a construct, but is using a hand write state modification https://github.com/slepher/cluster_booter/blob/master/src/cluster_booter.erl#L44-L52 |
i just modify your codes
why? |
by the way
will help you to locate the error. |
First, thanks for the answer. But I think you are not getting what I'm trying to achieve. Your modified example does not do what I want. I want to be able to return You version would work with a simple state monad, no need for the error monad. I think in Haskell terms, that is called applying a monad state transformation to an error monad or the other way around (adding error handling to a state monad) ... |
replace
with
and at last,
state_m:run will retrun {Result, State} if you get some error
if not, you will get
|
doesn't work, something is still missing, the error transformer is not stripping the Full example:
|
just use
why this code is wrong?
type of monad_state:modify is (s-> s) -> StateT s Either e a -> StateT s Either e () juse use
|
first, many thanks for your patience. It might be my lack of grasp of monads or we are still talking about different things. Given this non-monadic versions:
I want a monadic version that roughly looks like this:
Any of the There might be bits missing, but the end result should be roughly that simple. No begin/end clauses in the monad, not if's or anything. Is that a valid monadic rewrite of the non-monadic version? And if it is, how do I achieve that with you library? |
write a adapter function
and then
it's no way to do static type&typeclass check in erlang. |
Could you provide an example how to combine a state_t and error_t monad, please?
What I'm looking for is that my function can return either
{ok, {Result, NewState}}
,{ok NewState}
or{error, Error}
.The text was updated successfully, but these errors were encountered: