Haskell: Something like the application `$` operator for "do" notation?
haskell
Solution
It is a precedence error.... (`$=`) is binding more tightly than (`$`). You can see this in the error message:
Couldn't match expected type `Maybe IdleCallback'
with actual type `a0 -> Maybe a0'
In the second argument of `($=)', namely `Just'
It thinks that the second argument of (`$=`) is simply `Just` (which is a valid Haskell type referencing a function). If you put parenthesis around the whole `Just`, including the `do`-block, it should work.
Problem
I'm supplying a function to `idleCallback` This notation works: ``` idleCallback $= Just (do modifyIORef world play postRedisplay Nothing) ``` Why doesn't this (seemingly similar) notation work? ``` idleCallback $= Just $ do modifyIORef world play postRedisplay Nothing ``` To save your hoogling, the types are: ``` ($=) :: HasSetter s => s a -> a -> IO () type IdleCallback = IO () data SettableStateVar a idleCallback :: SettableStateVar (Maybe IdleCallback) postRedisplay :: Maybe Window -> IO () modifyIORef :: IORef a -> (a -> a) -> IO () ``` GHC says: ``` Couldn't match expected type `Maybe IdleCallback' with actual type `a0 -> Maybe a0' In the second argument of `($=)', namely `Just' In the expression: idleCallback $= Just In a stmt of a 'do' block: idleCallback $= Just $ do { modifyIORef world play; postRedisplay Nothing } ``` Can this be written without wrapping the `do` block in parenthesis?