-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add evalState
(to Control.Functor.Linear
)
#404
Comments
I'm not sure that |
Maybe I can do without it, but I didn't see how because of the |
Replacing response type `Ur b` by simply `b` also checks and enables uses like ```haskell let (i, _) = HashMap.empty 100 (\ env -> runState (eval e) env) ``` (see issue tweag#404). Caveat: I am relying on the linea type checker (which might be in alpha state, dunno), so there might be reasons unknown to me why this generalization is invalid. Test suite passes, though.
I just tried to generalize the response type of So if this is an admissible generalization, the need for |
I ain't... |
Use case: stateful interpreter (`eval`) for C-like expressions `e`: ```haskell let Ur value = HashMap.empty capacity (\ env -> move (evalState (eval e) env)) ``` This pattern breaks the "jail" set by the type signature of `HashMap`-allocation: ```haskell empty :: Int -> (HashMap k v %1 -> Ur b) %1 -> Ur b ``` `HashMap` is not `Movable` but `Consumable`, so we can get rid of it before `move`ing the result to `Ur`.
Use case: stateful interpreter (`eval`) for C-like expressions `e`: ```haskell let Ur value = HashMap.empty capacity (\ env -> move (evalState (eval e) env)) ``` This pattern breaks the "jail" set by the type signature of `HashMap`-allocation: ```haskell empty :: Int -> (HashMap k v %1 -> Ur b) %1 -> Ur b ``` `HashMap` is not `Movable` but `Consumable`, so we can get rid of it before `move`ing the result to `Ur`.
Use case: stateful interpreter (`eval`) for C-like expressions `e`: ```haskell let Ur value = HashMap.empty capacity (\ env -> move (evalState (eval e) env)) ``` This pattern breaks the "jail" set by the type signature of `HashMap`-allocation: ```haskell empty :: Int -> (HashMap k v %1 -> Ur b) %1 -> Ur b ``` `HashMap` is not `Movable` but `Consumable`, so we can get rid of it before `move`ing the result to `Ur`.
@aspiwack : I am back to If you have other ideas how to write https://gist.github.com/andreasabel/f5c877491d32b653efba44cb283ba490#file-interpretermain-hs , please let me know. |
Use case: stateful interpreter (`eval`) for C-like expressions `e`: ```haskell let Ur value = HashMap.empty capacity (\ env -> move (evalState (eval e) env)) ``` This pattern breaks the "jail" set by the type signature of `HashMap`-allocation: ```haskell empty :: Int -> (HashMap k v %1 -> Ur b) %1 -> Ur b ``` `HashMap` is not `Movable` but `Consumable`, so we can get rid of it before `move`ing the result to `Ur`.
evalState
is a common use-case of the state monad.Probably there should also be
evalStateT
.The text was updated successfully, but these errors were encountered: